Skip to content

Instantly share code, notes, and snippets.

@notesbytom
Last active July 21, 2017 16:35
Show Gist options
  • Save notesbytom/e8d9661d6e202dff9d5f9ff70045351b to your computer and use it in GitHub Desktop.
Save notesbytom/e8d9661d6e202dff9d5f9ff70045351b to your computer and use it in GitHub Desktop.
Mandatory Named Parameters for PowerShell Script File
# comment allowed before script param() statement
param([Parameter(Mandatory=$true)] $a, $b)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
"`$a = $a, `$b = $b"
$args
$MyInvocation
$PSBoundParameters
Exit
@notesbytom
Copy link
Author

Require a parameter for PowerShell script file. I believe the param() statement must be the first real statement in the file other than comments.
Typical statements like setting Error Action Preference and Strict Mode must come AFTER the "script" level param() statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment