Error handling
hi
how catch exception when working params . below script , if run
myscript.ps1 - u 1
it work.
if run
myscript.ps1 -u
i exception error. rather call usage function. looking way test if argument has been parse parameter ?
param ( $user, $logout, $report) function usage{ " random message " } if ($psboundparameters.get_count() -ge 1) # check see if have params { if ($psboundparameters.values -eq $null ) # trying check if params have value \ argument {"no args"} else {'parameters have been provided' } } else { usage }
you might want check out capabilities of decorating parameters attributes determine how should handled. here article:
http://technet.microsoft.com/en-us/library/dd347600.aspx
you can make parameters mandatory , include message each well.
fr3dd
Windows Server > Windows PowerShell
Comments
Post a Comment