VMware Cloud Community
inderraw
Contributor
Contributor

snapshot via script

Hi Team,

How to take snapshot multiple vm via power cli script vmware.

0 Kudos
9 Replies
Macleud
Enthusiast
Enthusiast

Hello.

You can use New-Snapshot. Here is a simple example.

 

 

$VmsName = "My_Vm-1", "My_Vm-2", "My_vm-3"
$namesnap = "My_Snapshot_Name"

foreach ($vm in $VmsName) {
$data= Get-Date -Format g
$Nsnap= "$namesnap"+"_"+"$data"
write-host "Created Vm $($Vm) Snapshot Memory"
Get-vm -name "$Vm" | New-Snapshot -Name "$namesnap" -Description "$Nsnap" -Memory:$true
}

 

 

Using the community search you will find many examples.

inderraw
Contributor
Contributor

Hi Macleud,

Thanks for your response, if i have to take snapshot without memory, what changes in script? Please

 

 

0 Kudos
ggggg_NZ
Contributor
Contributor

Hi there. 

just change the memory parameter to false

-Memory:$false
0 Kudos
Macleud
Enthusiast
Enthusiast

Or you can remove the parameter -Memory:$true

 

 

$VmsName = "My_Vm-1", "My_Vm-2", "My_vm-3"
$namesnap = "My_Snapshot_Name"

foreach ($vm in $VmsName) {
$data= Get-Date -Format g
$Nsnap= "$namesnap"+"_"+"$data"
write-host "Created Vm $($Vm) Snapshot Memory"
Get-vm -name "$Vm" | New-Snapshot -Name "$namesnap" -Description "$Nsnap"
}

 

 

Also, you can take virtual machine names from csv or txt file.

There are many examples in this community and on the Internet.

inderraw
Contributor
Contributor

Thanks, it will for me...

0 Kudos
inderraw
Contributor
Contributor

Hi,

Can i import csv file (vm list), instead of typing vm name in script?

 

0 Kudos
Macleud
Enthusiast
Enthusiast

Hi.

You will need to create a csv file with a "name" column.

 

$pathVms = 'C:\Desktop\Vms.csv'
$VmsAll  = Import-Csv $pathVms -Delimiter ","
$VmsName = $VmsAll.Name
$namesnap = "My_Snapshot_Name"
foreach ($vm in $VmsName) {
$data= Get-Date -Format g
$Nsnap= "$namesnap"+"_"+"$data"
write-host "Created Vm $($Vm) Snapshot Memory"
Get-vm -name "$Vm" | New-Snapshot -Name "$namesnap" -Description "$Nsnap"
}

 

 

0 Kudos
inderraw
Contributor
Contributor

Hi,

Thanks for support, if same with import vm in csv file, how to take without memory snapshot.

0 Kudos
Macleud
Enthusiast
Enthusiast

Hi.

No snapshot memory.

 

$pathVms = 'C:\Desktop\Vms.csv'
$VmsAll  = Import-Csv $pathVms -Delimiter ","
$VmsName = $VmsAll.Name
$namesnap = "My_Snapshot_Name"
foreach ($vm in $VmsName) {
$data= Get-Date -Format g
$Nsnap= "$namesnap"+"_"+"$data"
write-host "Created Vm $($Vm) Snapshot"
Get-vm -name "$Vm" | New-Snapshot -Name "$namesnap" -Description "$Nsnap"
}

 

 

If you need a snapshot with memory, then you need to add the parameter -Memory:$true

0 Kudos