How to I remove all $excluededVms from $vms??
[System.Collections.ArrayList]$excluededVms = get-content E:\scripts\delSnapshots\ExceptionsList.txt
[System.Collections.ArrayList]$vms = get-vm | Select-Object Name
In that case, can't you just do?
$vms = Get-VM | where{$excludedVMs -notcontains $_.Name} | Select -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
# Example
# vm1
# vm2
# vm3
$excludedVMs = New-Object System.Collections.ArrayList($null)
Get-Content -Path .\vmnames.txt | ForEach-Object -Process {
$excludedVMs.Add($_) | Out-Null
}
$excludedVMs
$excludedVMs.Remove('vm2')
$excludedVMs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
As far as I can see, you remove from $excludedVMs list, but they must be removed from $vms list.
This works for me: $excludedVMs.Remove("xxxx")
This do not work for me: $vms.Remove("xxx")
I want vm´s from $excludedVMs do be removed from $vms.
In that case, can't you just do?
$vms = Get-VM | where{$excludedVMs -notcontains $_.Name} | Select -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference