views:

88

answers:

3

If you were to make a tool that:

  1. sys-admins would use (e.g. system monitoring or backup/recovery tools)
  2. has to be script-able on Windows

Would you make the tool:

  1. A command-line interface tool?
  2. PowerShell cmdlet?
  3. GUI tool with public API?

I heard PowerShell is big among sys-admins, but I don't know how big compared to CLI tools.

A: 

Python.

Ideally suited for command-line applications and system administration. Easier to code than most shells. Also, runs faster than most shells.

S.Lott
yes, but not integrated (or easily integratable) with ms software.
x0n
@x0n: What? Do you have specifics on this? It's news to me and the entire IronPython community.
S.Lott
hmm; knee jerk answer from you I think. I'm not saying that grammatically powershell is a better langauge (it's not) but in other terms: does the microsoft common engineering criteria (CEC) specify that all microsoft products must support language bindings and/or integrated support for ironpython? No. It does for powershell.
x0n
specifics: http://www.microsoft.com/cec/en/us/cec-overview.aspx#man-windows this means that in real terms, there is 1st class support for powershell in pretty much every server product coming out of redmond, from sharepoint, iis, sccm, exchange, cluster, sql, activedirectory, dns, ocs, windows, etc etc.
x0n
@x0n: I don't understand your first claim. Your second ("powershell is supported") seems irrelevant -- it doesn't seem to support your first claim. Your initial claim "(not integrated (or easily integratable)" is less clear. Do you have specifics on Iron Python being "not integrated (or easily integratable)" with MS Software? That's the claim I'm trying to pin down.
S.Lott
To clarify: supported = integrated. integrated = provides binary module or snapin surfacing task-oriented native cmdlets for powershell. No team (that I know of) within Microsoft are shipping native ironpython bindings for their products. Both powershell and IP can work with the CLR, but powershell cmdlets are way easier than writing .NET calls. Clearer?
x0n
@x0n: "IP can work with the CLR". Yet, "not integrated". Nope. Not clear at all. It can't be both. Which is it?
S.Lott
@s.lott you are becoming argumentative, pedantic and petty. I am not slamming IronPython, I quite like it. You know what I mean, and if you choose to ignore that, go for it. You're wasting your time (and anyone elses' who is reading these comments.) Do you have any idea what a Cmdlet is and why it represents a more integrated product solution over working directly with the BCL? If not, go find out. Your ignorance is starting to show.
x0n
@x0n: I'm not arguing. I'm asking. You made a statement without any supporting evidence. And you made what appears to be a contradictory statement. Please help me understand these two statements. I'm not arguing. I'm asking. Asking questions. Hoping for answers. cmdlets don't seem to be the point; you said Iron Python is "not itegrated". Why did you say that? What does that mean?
S.Lott
+7  A: 

PowerShell.

With PowerShell you have your choice of creating reusable commands in either PowerShell script or as a binary PowerShell cmdlet. PowerShell is specifically designed for commmand line interfaces supporting output redirection as well as easily launching EXE's and capturing their output. One of the best parts about PowerShell IMO is that it standardizes and handles parameter parsing for you. All you have to do is declare the parameters for your command and PowerShell provides the parameter parsing code for you including support for typed, optional, named, positional, mandatory, pipeline bound, etc. For example, the following function declarations shows this in action:

function foo($Path = $(throw 'Path is required'), $Regex, [switch]$Recurse)
{
}

# Mandatory
foo 
Path is required

# Positional
foo c:\temp '.*' -recurse

# Named - note fullname isn't required - just enough to disambiguate
foo -reg '.*' -p c:\temp -rec

PowerShell 2.0 advanced functions provide even more capabilities such as parameter aliases -CN alias for -ComputerName, parameter validation [ValidateNotNull()] and doc comments for usage and help e.g.:

<#
.SYNOPSIS
    Some synopsis here.
.DESCRIPTION
    Some description here.
.PARAMETER Path
    The path to the ...
.PARAMETER LiteralPath
    Specifies a path to one or more locations. Unlike Path, the value of 
    LiteralPath is used exactly as it is typed. No characters are interpreted 
    as wildcards. If the path includes escape characters, enclose it in single
    quotation marks. Single quotation marks tell Windows PowerShell not to 
    interpret any characters as escape sequences.
.EXAMPLE
    C:\PS> dir | AdvFuncToProcessPaths
    Description of the example
.NOTES
    Author: Keith Hill
    Date:   June 28, 2010    
#>
function AdvFuncToProcessPaths
{
    [CmdletBinding(DefaultParameterSetName="Path")]
    param(
        [Parameter(Mandatory=$true, Position=0, ParameterSetName="Path", 
                   ValueFromPipeline=$true, 
                   ValueFromPipelineByPropertyName=$true,
                   HelpMessage="Path to bitmap file")]
        [ValidateNotNullOrEmpty()]
        [string[]]
        $Path,

        [Alias("PSPath")]
        [Parameter(Mandatory=$true, Position=0, ParameterSetName="LiteralPath", 
                   ValueFromPipelineByPropertyName=$true,
                   HelpMessage="Path to bitmap file")]
        [ValidateNotNullOrEmpty()]
        [string[]]
        $LiteralPath
    )
    ...
}

See how the attributes give you finer grained control over PowerShell's parameter parsing engine. Also note the doc comments that can be used for both usage and help like so:

AdvFuncToProcessPaths -?
man AdvFuncToProcessPaths -full

This is really quite powerful and one of the main reasons I stopped writing my own little C# utility exes. The parameter parsing wound up being 80% of the code.

Keith Hill
If Windows is the target, I honestly don't think there's a better alternative than PowerShell. Personally, I think its biggest strength is how easy it makes remoting. I hate remoting since in my experience there was always a process you had to carry out before you could start it, which just took time. Now with PowerShell all you have to do is `Enable-PSRemoting` and you're good to go.
George Howarth
Yeah there is a *lot* to like about PowerShell, including remoting, but my answer was already getting kind of long. :-)
Keith Hill
A: 

I always create a command line tool first:

  • It is far easier to automate / incorporate into scripts than a GUI (much less work than producing an API)
  • It will run in pretty much all windows machines (including older machines without Power shell installed)

Although power shell is a great tool for sysadmins, I don't yet think it is widely spread enough to escape the need to also produce a traditional command line tool as well - hence I always make a command line tool first (although I might also choose to go onto produce a PowerShell cmdlet).

Similarly, although a well thought out API may be easier for scripting, your API will place restrictions on what languages users can script in and so it is always a good idea to additionally provide a command line tool as a fallback / easy alternative.

Kragen