Created
March 20, 2019 19:06
-
-
Save techthoughts2/6e603017e5aed88b63239b604091f4e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #--------------------------------------------------------------- | |
| # 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