I use this script to create snapshot of servers from an excel list. Can someone help with changing this so that it looks at a list of IP Addresses instead?
Checking to see if I understood the question.
You want to find the VMs based on their IP addresses, which are in the CSV ?
And once you have the VM, do the same snapshot removal/creation steps.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is correct.
Try something like this
The link between the VMs and the IP addresses is stored in a hash table for easy reference.
$ipTab = @{}
foreach($vm in (Get-VM | Where {$_.Guest.IPAddress})){
$vm.Guest.IPAddress | %{
$ipTab.Add($_,$vm)
}
}
$snapName = "maintenance_mm_dd_yy"
Import-Csv iplist.csv -UseCulture | %{
if($ipTab.ContainsKey($_.IPAddress)){
$snap = Get-Snapshot -VM $ipTab[$_.IPAddress] -ErrorAction SilentlyContinue
if($snap){
Remove-Snapshot -Snapshot $snap -Confirm:$false
}
New-Snapshot -Name $snapName -VM $ipTab[$_.IPAddress] -Confirm:$false
}
}
Note that the script doesn't contain any extra logic to handle VMs that have more than 1 IP address
The same same snapshot will be taken multiple times.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference