Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#---------------------------------------------------------------
# Evaluating if a Parameter Set has been used
if ($PSCmdlet.ParameterSetName -eq 'InstanceId') {
$target = @{Key = 'instanceids'; Values = $managedInstanceId}
}
else {
$target = @{Key = "tag:$tagName"; Values = $TagValue}
}
#---------------------------------------------------------------
#controlling multiple dependencies of parameter choices example
[Parameter(ParameterSetName = 'ScriptblockTag', Mandatory = $true)]
[Parameter(ParameterSetName = 'ScriptPathTag', Mandatory = $true)]
[ValidateSet('prod', 'prod-braveheart', 'gamma', 'alpha')]
[string]$TagValue,
[Parameter(ParameterSetName = 'ScriptblockInstanceId', Mandatory = $true)]
[Parameter(ParameterSetName = 'ScriptPathInstanceId', Mandatory = $true)]
[string[]]$ManagedInstanceId,
[Parameter(ParameterSetName = 'ScriptblockInstanceId', Mandatory = $true)]
[Parameter(ParameterSetName = 'ScriptPathInstanceId', Mandatory = $true)]
[string]$AWSAccountID,
[Parameter(ParameterSetName = 'ScriptblockTag', Mandatory = $true)]
[Parameter(ParameterSetName = 'ScriptblockInstanceId', Mandatory = $true)]
[string]$Scriptblock,
[Parameter(ParameterSetName = 'ScriptPathTag', Mandatory = $true)]
[Parameter(ParameterSetName = 'ScriptPathInstanceId', Mandatory = $true)]
#---------------------------------------------------------------
#validating a parameter input for a file via a validation script
[ValidateScript( {
if (-Not ($_ | Test-Path) ) {
throw "File or folder does not exist"
}
if (-Not ($_ | Test-Path -PathType Leaf) ) {
throw "The Path argument must be a file. Folder paths are not allowed."
}
if ($_ -notmatch "(\.ps1)") {
throw "The file specified in the path argument must be either of type ps1"
}
return $true
})]
[System.IO.FileInfo]$ScriptPath,
#---------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.