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

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS