{"id":1953,"date":"2013-06-17T01:39:42","date_gmt":"2013-06-17T01:39:42","guid":{"rendered":"https:\/\/pipe2text.com\/?page_id=1953"},"modified":"2014-02-01T21:37:46","modified_gmt":"2014-02-01T21:37:46","slug":"using-powershell-to-remove-virtual-machine-snapshots-in-vmware-esxi-4-1","status":"publish","type":"page","link":"https:\/\/pipe2text.com\/?page_id=1953","title":{"rendered":"Using PowerShell to Remove Virtual Machine Snapshots in VMware ESXi 4.1"},"content":{"rendered":"<p><a id=\"_GoBack\"><\/a>Hi All,<\/p>\n<p>VMware snapshots can be a very good insurance policy when making changes to a VM. Its also important to make sure not to leave old snapshots laying around as this will cause you problems later. To get a report of snapshots using powershell please see my other blog <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> . In this blog I will explain how to remove Virtual Machine snapshots using PowerShell. We will be using the \u201cRemove-Snapshot\u201d cmdlet and piping it to the \u201cGet-Snapshot\u201d in the examples below. To do anything with PowerShell in VMware you will need to download and 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>To view the snapshots for a Virtual Machine before you remove them, you can type the following command replacing <em>VMname<\/em> with the name of your Virtual Machine:<\/p>\n<p>Get-Snapshot <em>VM<\/em><em>name<\/em> | select name,id<\/p>\n<p>In the command above, I select to see the name and id which will give you a list of the servers snapshot names and snapshot IDs. The ID will be important to note when being asked to confirm the removal of the snapshot when running the &#8220;Remove-Snapshot&#8221; cmdlet.<\/p>\n<p>To remove the snapshots found in the command above, we can use the \u201cGet-Snapshot\u201d cmdlet and pipe it to the \u201cRemove-Snapshot\u201d cmdlet as shown below, replacing <em>VMname<\/em> with the name of your Virtual Machine (This will remove all snapshots for the specified Virtual Machine):<\/p>\n<p>Get-Snapshot <em>VMname<\/em><em> <\/em>| Remove-Snapshot<\/p>\n<p>You will then be asked to confirm the deletion of the snapshot (you will see that the confirmation uses the ID that we selected to view earlier). Type \u201cY\u201d and press enter to confirm the removal. If you did not want to be asked to confirm the removal you could use the \u201cconfirm\u201d parameter as shown on the command below:<\/p>\n<p>Get-Snapshot <em>VMname<\/em><em> <\/em>| Remove-Snapshot -confirm:$false<\/p>\n<p>If you wanted to see what happens by typing the command above without having any snapshots removed, the \u201cRemove-Snapshot\u201d cmdlet supports the use of the \u201cwhatif\u201d parameter. You could type the following to see what will happen without actually removing anything:<\/p>\n<p>Get-Snapshot <em>VMname<\/em><em> <\/em>| Remove-Snapshot \u2013whatif<\/p>\n<p>If you wanted to remove snapshots for multiple VMs and you had your Virtual Machines organized in folders, you could type the following command to remove all snapshots for all Virtual Machines located in the \u201cMy Lab\u201d folder:<\/p>\n<p>Get-VM -location &#8220;My Lab&#8221; | Get-Snapshot | Remove-Snapshot -confirm:$false<\/p>\n<p>In the above command, we use the \u201cGet-VM\u201d cmdlet to get all of the Virtual machines in the \u201cMy Lab\u201d folder. We then pipe it to the \u201cGet-Snapshot\u201d cmdlet to get the snapshots for the Virtual machines in the \u201cMy Lab\u201d folder. Next we pipe this to the \u201cRemove-Snapshot\u201d cmdlet to remove all snapshots found on Virtual Machines in the \u201cMy Lab\u201d folder.<\/p>\n<p>If you wanted to remove all VM snapshots regardless of folder location, you could remove the -location parameter from the command in the last example. This will remove all snapshots for VMs that have them. The snapshots will be removed from each VM one by one.\u00a0The command is as follows:<\/p>\n<p><span style=\"color: #000000; font-size: medium;\">Get-VM | Get-Snapshot | Remove-Snapshot -confirm:$false<\/span><\/p>\n<p>I hope this helps. If you have any questions or feedback, please leave a comment. Thanks.<\/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 Gracefully Shut Down Multiple Virtual Machines in VMware\" href=\"https:\/\/pipe2text.com\/?page_id=1889\"><strong>Using PowerShell to Gracefully Shut Down Multiple Virtual Machines in VMware<\/strong><\/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><\/p>\n<p><strong><a title=\"Using PowerShell to Take Virtual Machine Snapshots in VMware\" href=\"https:\/\/pipe2text.com\/?page_id=2286\"><strong>Using PowerShell to\u00a0Create Virtual Machine Snapshots in VMware<\/strong><\/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. Its also important to make sure not to leave old snapshots laying around as this will cause you problems later. To get a &hellip; <a href=\"https:\/\/pipe2text.com\/?page_id=1953\">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-1953","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/1953","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=1953"}],"version-history":[{"count":14,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/1953\/revisions"}],"predecessor-version":[{"id":2299,"href":"https:\/\/pipe2text.com\/index.php?rest_route=\/wp\/v2\/pages\/1953\/revisions\/2299"}],"wp:attachment":[{"href":"https:\/\/pipe2text.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}