Skip to content

Instantly share code, notes, and snippets.

@lukemurraynz
Last active December 13, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukemurraynz/7931cfa391b7562879b383f5dab829ba to your computer and use it in GitHub Desktop.
Save lukemurraynz/7931cfa391b7562879b383f5dab829ba to your computer and use it in GitHub Desktop.
Using PowerShell to remove Snapshots from Virtual Machines in vSphere
<#
Author: Luke Murray (Luke.Geek.NZ)
Version: 1.0
requires -Version 1
requires -PSSnapin VMware.VimAutomation.Core
Purpose: To remove all VMWare Snapshots on any Windows Server entered into the SnapshotRemoval.txt document.
The following Variables will need to be set for your environment:
$vsphereserver = Your vSphere Server Bane
$VMGuestName = The location of the TXT document with the VM names, in my example its c:\Scripts\SnapshotRemoval.txt
#>
Add-PSSnapin -Name VMware.VimAutomation.Core
$vsphereserver = VSPHERESERVER
$VMGuestName = Get-Content -Path C:\Scripts\SnapshotRemoval.txt
Connect-VIServer -Server $vsphereserver
Get-VM $VMGuestName |
Get-Snapshot |
Remove-Snapshot -Confirm:$false
Clear-Content -Path C:\Scripts\SnapshotRemoval.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment