Powershell, PowerCLI Snapshot and Recompose Script

This is the code I’m working on for vCenter, ESX, and VMware View. It removes all snapshots, takes a snapshot, and then recomposes. I created it so that our pool can stay up to date on WSUS updates and virus updates without having to manually recompose all the time.


### Snapshot and Recompose PowerCLI Script ###
### Written by Greg Carriger 06-01-2011 ###
### Must be run from the View Connection Server ###

### Set-ExecutionPolicy RemoteSigned (allow scripts to be run)

##Set Variables
$strTargetVM = "MasterVM"
$strVCServer = "vCenterComp"
$strService = "username"
$strPassword = "PASSWORD"
$strPoolname = "TestPool"
$strSnapshotName = "composer"
$strView = "ViewConnectionServer"
$strDomain = "Domain.com"

## Connect to vCenter
Connect-VIServer –Server $strVCServer –Protocol https –User $strService –Password $strPassword

## Remove Snapshots
Get-Snapshot –VM $strTargetVM | Remove-Snapshot -confirm:$false

## Create Snapshot
Get-VM -Name $strTargetVM | New-Snapshot -Name $strSnapshotName

## Disconnect from vCenter
Disconnect-VIServer -Server $strVCServer

This next part is untested still, but I’ll be trying it out soon.


## Update Pool Settings
## Untested
Update-AutomaticLinkedClonePool
-pool_id $strPoolname
-parentVMPath $strParentVMPath
-parentSnapshotPath /$strSnapshotName
-minimumcount 2
–maximumcount 10
–nameprefix *

## Recompose
## Untested
Get-DesktopVM
-pool_id $strPoolname |
Send-LinkedCloneRecompose
-parentVMPath $strParentVMPath
-parentSnapshotPath /$strSnapshotName
-forceLogoff:$true
-stopOnError:$true

Advertisements

5 thoughts on “Powershell, PowerCLI Snapshot and Recompose Script

    1. gregcarriger Post author

      Hi Kham. I really liked being a VMware View Admin, but unfortunately I’m not one anymore. I don’t have a copy of it anymore, but I did get it to work. I never put the script into production because when dealing with windows updates and such, I didn’t want to risk a recompose failing at midnight, and having to get up and fix it. I ended up just doing it manually as I didn’t manage that many pools.

      Reply
  1. Pingback: VMware View Pool Recompose PowerCLI Script | Sean's IT Blog

  2. steven gillis

    Greg, we are a small public library using EXSI without View (which would be cost prohibitive). I think we have found scripts to create linked clones using SSH scripts, and also remove them through another scripting process. Would something like your script work w/o View? I would love the capability to recompose.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s