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

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Windows server 2012 r2 inplace upgrade failed