Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Info {
- [cmdletbinding()]
- param(
- [parameter(ParameterSetName="System")]
- [ValidateSet("Server","Desktop","Mainframe")]
- [string]$System
- )
- DynamicParam {
- if($PSBoundParameters["System"] -ne $null) {
- switch($System){
- "Server" {
- $OSList = "WS2008R2","WS2012","WS2012R2","RHEL60" #...
- }
- "Desktop" {
- $OSList = "WinXP","Win7","Win8","Win81","Win10"
- }
- "Mainframe" {
- $OSList = "zOS","zVM","zVSE"
- }
- }
- $validateSetAttribute = new-object ValidateSet -ArgumentList $OSList
- $parameterAttribute = [parameter]::new()
- $parameterAttribute.ParameterSetName = "System"
- $attributeCollection = [System.Collections.ObjectModel.Collection[System.Attribute]]::new()
- $attributeCollection.Add($validateSetAttribute)
- $attributeCollection.Add($parameterAttribute)
- $operatingSystemParam = [System.Management.Automation.RuntimeDefinedParameter]::new('OS',[string],$attributeCollection)
- $paramDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new()
- $paramDictionary.Add('OS', $operatingSystemParam)
- $paramDictionary
- }
- }
- process {
- "System: $System, OS: $($PSBoundParameters['OS'])"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment