top of page

PowerShell Parameters

#Format for requiring multiple parameters to be entered

#Would be declared at the start of the script this would 

#assure that the input variables the script requires to #execute correctly has been entered. 

​

[CmdletBinding()]
Param(
    [parameter(Mandatory=$true)]
    [String]$ComputerName,
    [parameter(Mandatory=$true)]
    [String]$UserName
)

Woman Studying
param2.PNG

Parameter declaration can have many options. The one below has been set to require input from the user when executing the script and assigns the value to the variable $computerNames. This allows for programmers to force some type of control to end users.

​

# Mandatory=$True <-- Statement says the script requires a input parameter

​

# Has to appear at the top of the script or function 

​

# The parameter input will assign the value to the $computerNames variable 
 
[CmdletBinding()]    
            
Param([Parameter(Mandatory=$True)][string]$computerNames)
       
Write-Output $computerNames

bottom of page