Hello,
I have been researching how to grab VM View Status (connected, available, startup, deleting, etc.). I have a script that leverages several capabilities to collect the proper information for determining the desktop statuses that one sees in View. However, it currently takes 3 seconds per VM. I need to get it under 1 second as I have 1000s of pooled VMs to collect. I've looked at doing this by scraping View but, its not a webpage, its flash page.
It does work and will work if you have 50-100 vms you want to poll every hour or 30 minutes but beyond that it takes too much work.
Essentially you need the following commands all run from the View server so you have access to View PowerCLI, as well as vSphere PowerCLI installed on View server.
vdmadmin.exe
Get-VM
Get-DesktopVM
LDAP Connection to ADAM DB
Gwmi Win32_ComputerSystem -Comp
I run those commands per VM into a variable to leverage the data
$poolVMs = get-vm *[name]*
$objGetVM = $poolVMs[$vmNum]
$objVDM = vdmadmin.exe -A -d $poolName -m $vmName -getstatus
$objGetDesktop = get-desktopvm -name $vmName
$LDAPPath = 'LDAP://' + $viewServer + ':389/OU=Servers,DC=vdi,DC=vmware,DC=int'
$LDAPEntry = New-Object DirectoryServices.DirectoryEntry $LDAPPath
# Create a selector and start searching from the path specified in $LDAPPath
$Selector = New-Object DirectoryServices.DirectorySearcher
$Selector.SearchRoot = $LDAPEntry
$Selector.Filter = "(&(objectClass=pae-VM)(iphostnumber=" + $vmName + ".serco.cms))"
$objADAM = $Selector.FindAll()
$objSession = Gwmi Win32_ComputerSystem -Comp $vmName
This is the set of if, elseif, else statements that provide the 'algorithm' to determine the status of the vm
if( $objVDM[8].Split(" ")[2] -eq 0 -and
$objGetVM.PowerState -eq "PoweredOn" -and
$objGetDesktop.hostname -and
$objGetDesktop.ipaddress -and
$objGetDesktop.isinpool -eq "true" -and
$objADAM[0].properties.'pae-vmstate' -eq "READY" -and
$objSession.username
){
$intConnected++
#Write-Host $vmName "Is Connected"
}
elseif ( $objADAM[0].properties.'pae-vmstate' -eq "DELETING"
){
$intDeleting++
#Write-Host $vmName "Is Deleting"
}
elseif ( !$objVDM -and
$objGetVM.PowerState -eq "PoweredOff" -and
!$objGetDesktop.ipaddress -and
$objGetDesktop.isinpool -eq "false" -and
!$objADAM[0]
){
$intProvisioning++
#Write-Host $vmName "Is Provisioning"
}
elseif ( !$objVDM -and
$objGetVM.PowerState -eq "PoweredOn" -and
$objGetDesktop.ipaddress -and
$objADAM[0].properties.'pae-vmstate' -eq "READY"
){
$intUnreachable++
#Write-Host $vmName "Is Agent Unreachable"
}
elseif ( !$objVDM -and
$objGetVM.PowerState -eq "PoweredOn" -and
$objGetDesktop.guestfullname -and
!$objGetDesktop.ipaddress -and
$objGetDesktop.isinpool -eq "true" -and
!$objADAM[0]
){
$intCustomizing++
#Write-Host $vmName "Is Customizing"
}
elseif ( $objGetDesktop.composerTask -eq "mkChkPoint" -and
$objADAM[0].properties.'pae-vmstate' -eq "CUSTOMIZING" -and
$objADAM[0].properties.'pae-svivmoperationstatus' -eq "scheduled"
){
$intCustomizingChkpnt++
#Write-Host $vmName "Is Customizing - Refreshing Checkpoint"
}
elseif ( !$objVDM -and
$objGetVM.PowerState -eq "PoweredOn" -and
!!$objGetDesktop.guestfullname -and
!$objGetDesktop.ipaddress -and
$objGetDesktop.isinpool -eq "true" -and
$objADAM[0]
){
$intStartup++
#Write-Host $vmName "Is Startup"
}
elseif ( !$objVDM -and
$objGetVM.PowerState -eq "PoweredOff" -and
!$objGetDesktop.ipaddress -and
$objGetDesktop.isinpool -eq "true" -and
$objADAM[0]
){
$intProvisioned++
#Write-Host $vmName "Is Provisioned"
}
else {
$intAvailable++
#Write-Host $vmName "Is Available"
}
I think i can speed up polling by using Get-View with filters instead of Get-VM
The reason I am sharing this is because I thought someone else could help speed up the process, thoughts on speeding it up, or know of another way.
My next steps:
- is to implement with Get-View
- Split up pool polling so speed up the time to complete but there is a problem due to limit of sessions to VIServer that I need to work with/around.
Does anyone have any support to this work you can provide?
I will attach my code and config files if anyone is interested.