Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

How to accept either VM Name or VM Object on the same paramenter

$
0
0

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 ?

 

    [CmdletBinding(DefaultParameterSetName='Folder')]

 

    

        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

        )


Viewing all articles
Browse latest Browse all 175326

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>