show vmware snapshots script

here’s a simple, little powershell script to show all of your snapshots.  you have to use the vmware vi toolkit and virtual center to do this.  i have mine going to a html file, in this example.

# =============================================================================
# NAME: VMSnapshots
# AUTHOR: Marcus C. Oh, Cox Communications, Inc.
# DATE  : 8/5/2008
# COMMENT: A real simple script to pull back snapshots of a VM.
# =============================================================================

$myVC = $Args[0]

If ($Args[0] -eq $null) {
    Write-Warning "Please provide a server name as an argument."
} else {
    $VCServer = Connect-VIserver -server $myVC -credential (Get-Credential $_.username)
    Get-VM -Server $VCServer | Get-Snapshot `
        | ConvertTo-Html -Property created,quiesced,powerstate,`
        @{label = "Note";expression = {If ($_.Description -ne ''){$_.Description}else{"None"}}},vm `
        -Title "VM Snapshots Report" > c:\temp\VMSnapshot.html
}

Comments

  1. I'm new to powershell, but a long time user of VBScript.

    How do I run this script?

    ReplyDelete
  2. well, the easy way to do it would be to save it as vmsnapshots.ps1 and then execute it from within a powershell console as ".\vmsnapshots.ps1".

    otherwise, from cmd prompt, you could preface it with "powershell .\vmsnapshots.ps1".

    ReplyDelete

Post a Comment