Mandatory Parameter
noun
say it: “MAN-duh-tor-ee puh-RAM-uh-ter” /ˈmændəˌtɔri pəˈræmətər/
A script or function input that must be given; when it's left out, PowerShell asks for it before running.
What is a mandatory parameter in PowerShell?
A mandatory parameter is one a script can't run without. Put [Parameter(Mandatory)] on the line above it, and when it's left out, PowerShell asks for its value before the script starts. A parameter has a default value or is mandatory, not both.
param(
[Parameter(Mandatory)]
[string]$Destination
)
# .\Backup-Folder.ps1
# Supply values for the following parameters:
# Destination: backup
In a sentence
- “Sam made -Destination a mandatory parameter, so the backup asks where to copy when he forgets to say.”
- “A mandatory parameter can't also have a default value.”
Level: Apprentice · More PowerShell terms at this level
Updated