Automation

 View Only
  • 1.  snapshot via script

    Posted Mar 16, 2023 08:05 PM

    Hi Team,

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



  • 2.  RE: snapshot via script

    Posted Mar 18, 2023 12:59 PM

    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.



  • 3.  RE: snapshot via script

    Posted Mar 20, 2023 07:57 PM

    Hi Macleud,

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

     

     



  • 4.  RE: snapshot via script

    Posted Mar 20, 2023 08:07 PM

    Hi there. 

    just change the memory parameter to false

    -Memory:$false


  • 5.  RE: snapshot via script

    Posted Mar 20, 2023 08:12 PM

    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.



  • 6.  RE: snapshot via script

    Posted Mar 20, 2023 08:16 PM

    Thanks, it will for me...



  • 7.  RE: snapshot via script

    Posted Mar 21, 2023 09:24 PM

    Hi,

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

     



  • 8.  RE: snapshot via script

    Posted Mar 22, 2023 06:25 AM

    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"
    }

     

     



  • 9.  RE: snapshot via script

    Posted Mar 22, 2023 06:57 PM

    Hi,

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



  • 10.  RE: snapshot via script

    Posted Mar 22, 2023 07:27 PM

    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