I stole some code from LucD from 2012 which took a Folder object, and added a second parameter to accept a VM object and then get its folder.
Much as PowerCLI cmdlets do, I would like my function to also accept a string or wildcard for the -VM parameter, on which I'd simply do a get-VM to retrieve the VM object.
What is the laziest way to accomplish this? Can I add a 3rd mutually exclusive parameter set for a [String] param with the same name as -VM ?
param(
[parameter(ParameterSetName='Folder', valuefrompipeline = $true,
position = 0,
HelpMessage = "Enter a folder")]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl[]]$Folder,
#[switch]$ShowHidden = $false,
[parameter(ParameterSetName='VM', valuefrompipeline = $true,
position = 0,
HelpMessage = "Enter a VM")]
[VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl[]]$VirtualMachine
#[switch]$ShowHidden = $false
)
Yes, OBN is a PowerCLI feature, not a PS feature.
A parameter alias can give another name to a parameter, not a different type.
The 1st solution in my post, with PSObject, is the one that I used quite often and is probably the simplest.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When you are referring OBN, you might want to have a look at my Home Made OBN post.
It describes my cheap method wby using PSObject, but also my MyOBN class solution.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow, that is complex very quickly. Is OBN a PowerCLI-specific feature and not native to PS5? I was naively hoping it was as simple as using aliases but for differing object types.
Yes, OBN is a PowerCLI feature, not a PS feature.
A parameter alias can give another name to a parameter, not a different type.
The 1st solution in my post, with PSObject, is the one that I used quite often and is probably the simplest.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference