Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. # Pass a mandatory parameter to a PowerShell script
  2.  
  3. # This example requests a single string, stored as a variable
  4. # e.g. .\passmandatoryparameter.ps1 -FavouriteColour Purple
  5. # If the parameter isn't provided (e.g. .\passmandatoryparameter.ps1), the script will request it,
  6. # but if nothing is passed the script will throw an error.
  7.  
  8. param(
  9. [Parameter(Mandatory=$true)]
  10. [string]$FavouriteColour
  11. )
  12.  
  13. Write-Host "You should only see me if you provided a string."
  14. Write-Host "By the way, you said your favourite colour is $FavouriteColour"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement