exports/Get-CVVirtualMachine.ps1


# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Method to retrieve the list of virtual machines in the CommCell.
.Description
This method is implemented with Powershell paging support.
Method to retrieve the list of virtual machines in the CommCell.

Output can be filtered by Protected/Unprotected status, active subclients of a client, and virtual machine Name.
.Example
PS C:\> {{ Add code here }}
 
{{ Add output here }}
.Example
PS C:\> {{ Add code here }}
 
{{ Add output here }}
 
.Inputs
System.Object
.Outputs
Outputs [PSCustomObject] representing a virtual machine.
.Link
https://docs.microsoft.com/en-us/powershell/module/commvaultpowershell/get-cvvirtualmachine
#>

function Get-CVVirtualMachine {
[Alias('Perform-CVVMBrowse')]
[CmdletBinding(DefaultParameterSetName='Default', PositionalBinding=$false)]
param(
    [Parameter()]
    [Alias('VMName')]
    [Commvault.Powershell.Category('Body')]
    [System.String]
    # Filter output to virtual machine Name.
    ${Name},

    [Parameter()]
    [Commvault.Powershell.Category('Body')]
    [System.Management.Automation.SwitchParameter]
    # Filter output by Protected virtual machines.
    ${Protected},

    [Parameter()]
    [Commvault.Powershell.Category('Body')]
    [System.Management.Automation.SwitchParameter]
    # Filter output by UnProtected virtual machines.
    ${UnProtected},

    [Parameter(ParameterSetName='ById')]
    [Commvault.Powershell.Category('Body')]
    [System.String]
    # Specify Id representing virtual machine GUID.
    ${Id},

    [Parameter(ParameterSetName='ByClientName')]
    [Commvault.Powershell.Category('Body')]
    [System.String]
    # Filter output by active subclients of ClientName.
    ${ClientName},

    [Parameter(ParameterSetName='ByClientId')]
    [Commvault.Powershell.Category('Body')]
    [System.Int32]
    # Filter output by active subclients of ClientId.
    ${ClientId},

    [Parameter(ParameterSetName='ByClientObject', ValueFromPipeline, ValueFromPipelineByPropertyName)]
    [Commvault.Powershell.Category('Body')]
    [System.Object]
    # Filter output by active subclients of ClientObject.
    ${ClientObject}
)

begin {
    try {
        $outBuffer = $null
        if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {
            $PSBoundParameters['OutBuffer'] = 1
        }
        $parameterSet = $PSCmdlet.ParameterSetName
        $mapping = @{
            Default = 'CommvaultPowershell.custom\Get-CVVirtualMachine';
            ById = 'CommvaultPowershell.custom\Get-CVVirtualMachine';
            ByClientName = 'CommvaultPowershell.custom\Get-CVVirtualMachine';
            ByClientId = 'CommvaultPowershell.custom\Get-CVVirtualMachine';
            ByClientObject = 'CommvaultPowershell.custom\Get-CVVirtualMachine';
        }
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
        $scriptCmd = {& $wrappedCmd @PSBoundParameters}
        $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
        $steppablePipeline.Begin($PSCmdlet)
    } catch {
        throw
    }
}

process {
    try {
        $steppablePipeline.Process($_)
    } catch {
        throw
    }
}

end {
    try {
        $steppablePipeline.End()
    } catch {
        throw
    }
}
}