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
)