PowerShell Parameters

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 <-- Statementt says the script requires a input parameter

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

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

#Format for requiring multiple parameters to be entered

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

)

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator