DaveWentzel.com            All Things Data

Writing Your Own Functions

 

The basic syntax is:
 
Function MyFunction {
#code
}
 
It can then be run from another script or the command line.  (Calling Functions)
 
Parameters
Function MyFunction {
Param([objecttype]$variable=default)
#code
}
 
The Param keyword is a csv list. 
 
Example:
Function WriteStrings {
Param([string]$var1="Hello",[string]$var2="World")
writehost "String is: $var1 $var2"
}
 
 

Add new comment