Power Shell Scripts

http://technet.microsoft.com/en-us/scriptcenter/dd742419

Explains Functions/Scripts/Args
http://devcentral.f5.com/weblogs/Joe/archive/2009/01/13/powershell-abcs---p-is-for-parameters.aspx

How to pass params:
param(
    [string] $optionalparam1, #an optional parameter with no default value
    [string] $optionalparam2 = "default", #an optional parameter with a default value
    [string] $requiredparam = $(throw ""requiredparam required."), #throw exception if no value provided
    [string] $user = $(Read-Host -prompt "User"), #prompt user for value if none provided
    [switch] $switchparam; #an optional "switch parameter" (ie, a flag)
    ) 

eg:

# Begin script foo.ps1
param([string]$foo = "foo", [string]$bar = $(Read-Host -promt "Bar Value"))
Write-Host "Arg: $foo"
Write-Host "Arg: $bar"
#  End script foo.ps1 


Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

Update Excel Sheet using C#, Where Excel not Installed on Server