Skip to content

Instantly share code, notes, and snippets.

@nmanzi
Created August 10, 2013 02:06
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 nmanzi/6198708 to your computer and use it in GitHub Desktop.
Save nmanzi/6198708 to your computer and use it in GitHub Desktop.
Function ViewVM-SetState {
[cmdletBinding()]
Param (
[parameter(Mandatory=$true)]
[string]$vm, #VM name
[parameter(Mandatory=$true)]
[ValidateSet("MAINTENANCE","READY","DELETING","ERROR")]
[string]$state #State to set the VM to
)
$ldapBaseURL = 'LDAP://localhost:389/'
$Machine_Id = (Get-DesktopVM -Name $vm).machine_id
$objMachine_Id = [ADSI]($ldapBaseURL + "cn=" + $Machine_Id + ",ou=Servers,dc=vdi,dc=vmware,dc=int")
switch ($state) {
"MAINTENANCE" {
$objMachine_Id.put("pae-vmstate", "MAINTENANCE")
}
"READY" {
$objMachine_Id.put("pae-vmstate", "READY")
}
"DELETING" {
$objMachine_Id.put("pae-vmstate", "DELETING")
}
"ERROR" {
$objMachine_Id.put("pae-vmstate", "ERROR")
}
default {
break
}
}
$objMachine_Id.setinfo()
Return ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment