VMware Cloud Community
thankujo8
Contributor
Contributor
Jump to solution

PowerCli Script to take snapshot of multiple VM's from CSV file

Dear Team,

We have requirement to take snapshot of more than 200 VM's during the patching cycle. Now we are managing it manually and this requirement is coming every month.

Is it possible to take snapshot of the VM's from a CSV or TXT file. Would appreciate if you can help us to find PowerCLI script to do it.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Assuming you have a CSV with a column VMName that contains all the targetted VMs, you could do

Import-Csv -Path .\vmnames.csv |
ForEach-Object -Process {
  Get-VM -Name $_.VMName | New-Snapshot -Name "Snapshot" -Confirm:$false
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Assuming you have a CSV with a column VMName that contains all the targetted VMs, you could do

Import-Csv -Path .\vmnames.csv |
ForEach-Object -Process {
  Get-VM -Name $_.VMName | New-Snapshot -Name "Snapshot" -Confirm:$false
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
thankujo8
Contributor
Contributor
Jump to solution

Thank you.. that was quick. just one clarification.

Once i executed the command, the results shows Powerstate as 'PoweredOff' (screenshot attached). any idea why this is showing 'PoweredOff' ?

Name Description PowerState
---- ----------- ----------
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff
Before-Patching-1... PoweredOff

 

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Taking a snapshot does not power off a VM.
Were these VMs already powered off before the snapshot?
I would need to see the actual code you used.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
thankujo8
Contributor
Contributor
Jump to solution

1) These VM's are in Powered-ON state

2) these VM's after taking snapshot are still in Powered-ON state

However, the result command shows the VM as powered-off. attaching the screenshot of the command i executed.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The PowerState property in the object returned by New-Snapshot and Get-Snapshot shows the powerstate of the VM when the snapshot was taken.
Not the current powerstate of the VM.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
thankujo8
Contributor
Contributor
Jump to solution

Thank you @LucD 

Reply
0 Kudos