{"id":2286,"date":"2013-11-26T21:54:39","date_gmt":"2013-11-26T21:54:39","guid":{"rendered":"https:\/\/pipe2text.com\/?page_id=2286"},"modified":"2014-02-01T21:38:46","modified_gmt":"2014-02-01T21:38:46","slug":"using-powershell-to-take-virtual-machine-snapshots-in-vmware","status":"publish","type":"page","link":"https:\/\/pipe2text.com\/?page_id=2286","title":{"rendered":"Using PowerShell to Create Virtual Machine Snapshots in VMware"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>VMware snapshots can be a very good insurance policy when making changes to a VM. In this blog I will explain how to use PowerShell to create VM snapshots in VMWare. We will be using the \u201cGet-VM\u201d cmdlet and piping it to the \u201cNew-Snapshot\u201d to accomplish this in the examples below. To do anything with PowerShell in VMware you will need to install VMware vSphere PowerCLI. You will then need to open PowerCLI connect to your VMWare vCenter server by typing \u201cConnect-VIServer <em>vCenterServerName<\/em>\u201d.<\/p>\n<p>First I will start with taking a snapshot of a single virtual machine. In this example we will simply use the \u201cGet-VM\u201d cmdlet and specify the name of the virtual machine. We then pipe it the \u201cNew-Snapshot\u201d cmdlet. I have added in the \u201cMemory\u201d and \u201cQuiesce\u201d parameters to snap the memory and quiesce the files. The \u201cName\u201d parameter is used to specify the name of the snapshot. In the command below\u00a0we will be calling the snapshot name \u201cPrePatch\u201d. Replace <em>VMname<\/em><em> <\/em> with the name of your VM and PrePatch with the name you would like to call the snapshot.<\/p>\n<p>Get-VM <em>VMname<\/em> | New-Snapshot -Memory -Quiesce -Name <em>PrePatch<\/em><\/p>\n<p>Once the command completes (time will vary depending on the size of your VM), you will have a snapshot of the virtual machine with the name you specified. For information viewing VM snapshots please see my other article<span style=\"font-size: medium;\"><a href=\"https:\/\/pipe2text.com\/?page_id=251\">Using PowerShell to get a list Virtual Machine Snapshots in VMware<\/a><\/span><strong><span style=\"font-size: medium;\"><a href=\"https:\/\/pipe2text.com\/?page_id=251\"> ESXi 4.1<\/a><\/span><\/strong><\/p>\n<p>Now that we know how to take a snapshot of one VM, let\u2019s apply this to taking snapshots of multiple virtual machines. If you have your VMs organized by folder in vCenter, you can easily take a snapshot of all VMs in the folder by specifying the location. In the example below, we take a snapshots of all virtual machines located under the \u201cMy Lab\u201d folder.<\/p>\n<p>get-vm -location &#8220;My Lab&#8221; | New-Snapshot -Memory -Quiesce -Name <em>PrePatch<\/em><\/p>\n<p>When the command above completes you will have a snapshot for each VM located in the \u201cMy Lab\u201d folder. Each Snapshot will be named &#8220;Prepatch&#8221;.<\/p>\n<p><strong>IMPORTANT NOTE: You <\/strong><strong>should<\/strong><strong> be careful with<\/strong><strong> the amount of Virtual Machines you snap at the same time<\/strong><strong>. Depending on your environment, <\/strong><strong>taking too many snapshots <\/strong><strong>at one time could wreak havoc on your storage or on your environment in gen<\/strong><strong>eral. <\/strong><strong>It <\/strong><strong>would be best to test this out on a limited number of VMs in your environment<\/strong><strong> or in a lab first.<\/strong><\/p>\n<p>Its also not a good idea to leave snapshots sitting around for too long. For information about removing virtual machine snapshots using PowerShell please see my other article <a title=\"Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1\" href=\"https:\/\/pipe2text.com\/?page_id=1953\">Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1<\/a>.<\/p>\n<p>I hope this helps. If you have any questions or feedback, please leave a comment.<\/p>\n<p>Related Links:<\/p>\n<p><strong><a title=\"Using PowerShell to get a list Virtual Machine Snapshots in VMware ESXi 4.1\" href=\"https:\/\/pipe2text.com\/?page_id=251\">Using PowerShell to get a list Virtual Machine Snapshots in VMware ESXi 4.1<\/a><\/strong><\/p>\n<p><a title=\"Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1\" href=\"https:\/\/pipe2text.com\/?page_id=1953\"><b>Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1<\/b><\/a><\/p>\n<p><strong><a title=\"Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File\" href=\"https:\/\/pipe2text.com\/?page_id=2018\">Using PowerShell to create a Virtual Machine Inventory in VMware and Export it to a CSV File<\/a><strong><\/strong><\/strong><\/p>\n<p><strong><strong><a title=\"Using PowerShell to View  Virtual Machine Disks (VMDK) Information in VMware and Export to a CSV File\" href=\"https:\/\/pipe2text.com\/?page_id=2635\">Using PowerShell to View\u00a0 Virtual Machine Disks (VMDK) Information in VMware and Export to a CSV File<\/a><\/strong><\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All, VMware snapshots can be a very good insurance policy when making changes to a VM. In this blog I will explain how to use PowerShell to create VM snapshots in VMWare. We will be using the \u201cGet-VM\u201d cmdlet &hellip; <a href=\"https:\/\/pipe2text.com\/?page_id=2286\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"class_list":["post-2286","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2286"}],"version-history":[{"count":12,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2286\/revisions"}],"predecessor-version":[{"id":2655,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/2286\/revisions\/2655"}],"wp:attachment":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}