Is there a way to exclude a VMhost with get-snapshot? I need to exclude VMs with GuestOS (Windows 7 \ XP) that sits on one VMHost.
I can use get-vm + Name or Guest OS filter but it will slow the entire query down.
connect-viserver XXXXX
$vm = get-vm
$snapshots = Get-Snapshot -VM $vm
foreach ( $snap in $snapshots )
{
if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) )
{
$Snap | Select-Object -Property *
@{N="HostName";E={$_.vm}},
@{N="SizeGB";E={[math]::Round($_.SizeGB)}},
@{N="CreatedOn";E={$($_.Created -replace $time)}}
$count++
}
}
Try replacing this line
$vm = get-vm
with
$esxName = "ToBeExcluded"
$vm = get-vm | Where {$_.VMHost.Name -ne $esxName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try replacing this line
$vm = get-vm
with
$esxName = "ToBeExcluded"
$vm = get-vm | Where {$_.VMHost.Name -ne $esxName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. I modified my script and is doing a test run(takes a while). I am measuring the performance, will report back in few hours.
$esxName1 = "csms1.example.com"
$esxName2 = "*esx*v.example.com"
$vm = get-vm | Where {$_.VMHost.Name -ne $esxName1 -and $_.VMHost.Name -notlike $esxName2}
Thank you!!