Hello,
i have a simple script that i am using to create and remove snapshot via task schedule and i would like to modify it to get the data from a csv file instead of a table. currently my script looks like this :
Connect-VIServer -Server xxxxx.xxxx
$VM = @(
"VM1"
"VM2"
"VM3"
)
foreach ($SnapshotToremove in $VM){
Get-Snapshot -VM "$SnapshotToremove" -Name "Backup" | Remove-Snapshot -Confirm:$false
}
im still a newbie at this, i'm sure its quite simple to achieve but i've been trying for a while now with no success. Can anyone suggest the best way to have it retrieve the data from an import .csv file ? Any help would be greatly appreciated
Thank You,
Is this the same question as in vmware snapshot creation/deletion automation - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
the question is similar indeed, i am able to use my script to create/remove snapshots with a task but i was asked to modify it by adding an import .csv instead of using a table. The script that is referenced in the other post is a bit too advanced for me and i couldn't fully comprehend it so thats why i didn't use it
Provided you have a CSV that looks like this
VMName
VM1
VM2
VM3
you could do
Import-Csv -Path .\vmnames.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
Get-Snapshot -VM $row.VMName -Name "Backup" | Remove-Snapshot -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this works like a charm, really appreciate your help. had to go lookup the pipelinevariable option so i could understand it better
thanks a bunch !