Param(
    [Parameter(Mandatory = $true, ParameterSetName = 'VMName')]
    [string[]]
    $VMName,

    [Parameter(Mandatory = $true, ParameterSetName = 'NewBuilds')]
    [switch]
    $NewBuilds,

    [Parameter(Mandatory = $true, ParameterSetName = 'All')]
    [switch]
    $All
)

Write-Verbose -Message "Connect to vCenter" -Verbose
Connect-ITDvCenter -Credential $Secret:ndgov_svcitdvmvcauto

switch ($PSCmdlet.ParameterSetName) {
    'VMName' {
        Write-Verbose -Message "Parameter Set VMName" -Verbose
        $VMs = Get-VM -Name $VMName
    }
    'NewBuilds' {
        Write-Verbose -Message "Parameter Set NewBuilds" -Verbose
        $VMs = Get-Folder -Name "_New Builds" | Get-VM
    }
    'All' {
        Write-Verbose -Message "Parameter Set All" -Verbose
        $VMs = Get-VM | Where-Object CreateDate -lt ((Get-Date).AddDays(-2))
    }
}

ForEach($VM in $VMs){
    try{
        Write-Verbose -Message ("Start " + $VM.Name) -Verbose
        Get-VM -Name $VM.Name | Select Uid
        Move-ITDVMwareVMToAppNameFolder -VMName $VM.Name -ErrorAction Stop -Verbose
    }
    catch {
        $error[0]
    }
}


Write-Verbose -Message "Disconnect from vCenter" -Verbose
Disconnect-ITDvCenter