I have a exported csv file in the form of:
VM
serv1
serv2
serv3
(The name of the file is snaps4.csv)
I want to delete the snapshots associated an vm in this csv file; however I cannot get anything to work. The closest I have come is by manually removing the header in the csv file (i.e. VM) and then using the get-content command.
$vms = Get-Content C:\scripts\Output\snaps.csv
Get-Snapshot -vm $vms | Remove-Snapshot -RemoveChildren -Confirm:$false
The above command works, but I have to remove the header first (which I'm fine with if I am doing this, but I am trying to automate this for our operations people and having a manual step is not ideal).
Anybody help me out? I know I'm just missing something simple here but cannot figure this out.
Did you try like this ?
Import-Csv C:\scripts\Output\snaps.csv | %{
Get-Snapshot -vm $_.VM | Remove-Snapshot -RemoveChildren -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you try like this ?
Import-Csv C:\scripts\Output\snaps.csv | %{
Get-Snapshot -vm $_.VM | Remove-Snapshot -RemoveChildren -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, that worked. I was forgetting the $_. in front of VM....was a long day yesterday.
I also was able to accomplish it with this:
$vms = Get-Content C:\scripts\Output\snaps.csv | select-object -skip 1
Get-Snapshot -vm $vms | Remove-Snapshot -RemoveChildren -Confirm:$false
Thanks!