Created
April 13, 2019 12:24
-
-
Save seanosullivanuk/e3ca10f0f86d7e35f0c48125c190ab5b to your computer and use it in GitHub Desktop.
Pass a mandatory parameter to a PowerShell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pass a mandatory parameter to a PowerShell script | |
# This example requests a single string, stored as a variable | |
# e.g. .\passmandatoryparameter.ps1 -FavouriteColour Purple | |
# If the parameter isn't provided (e.g. .\passmandatoryparameter.ps1), the script will request it, | |
# but if nothing is passed the script will throw an error. | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$FavouriteColour | |
) | |
Write-Host "You should only see me if you provided a string." | |
Write-Host "By the way, you said your favourite colour is $FavouriteColour" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment