Hi all
I have a code for citrix farm that calculates available licenses. That all works fine. I just want some sort of auto refresh incorporated, i tried using timer and do a button perform click type of thing, but realized that my timer runs only once without the whole while loop. Does anyone have any suggestions on this?
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $Server = "ctxlcw8k1v" $otherLicenses = "385" $Pool = Get-WmiObject -class "Citrix_GT_License_Pool" -Namespace "ROOT\CitrixLicensing" -ComputerName $Server # Calculate licenses in use, total number of licenses and percentage currently in use $InUse = ($Pool | Measure-Object -Property InUseCount -sum).Sum $Installed = (($Pool | Measure-Object -Property Count -sum).Sum) - $otherLicenses $Percentage = [math]::round(($InUse/$Installed)*100,2) $left = $installed-$inuse $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Citrix Licenses Count" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.Font = New-Object System.Drawing.Font("Times New Roman", "11") $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "R") {$RefreshButton.PerformClick()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "C") {$objForm.Close()}}) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(20,40) $objLabel.Size = New-Object System.Drawing.Size(280,20) $objLabel.Text = "Licenses left: $left/$installed (In use: $percentage%)" $objForm.Controls.Add($objLabel) $RefreshButton = New-Object System.Windows.Forms.Button $RefreshButton.Location = New-Object System.Drawing.Size(75,120) $RefreshButton.Size = New-Object System.Drawing.Size(75,23) $RefreshButton.Text = "Refresh" $RefreshButton.Add_Click({ $Pool = Get-WmiObject -class "Citrix_GT_License_Pool" -Namespace "ROOT\CitrixLicensing" -ComputerName $Server $InUse = ($Pool | Measure-Object -Property InUseCount -sum).Sum $Installed = (($Pool | Measure-Object -Property Count -sum).Sum) - $otherLicenses $Percentage = [math]::round(($InUse/$Installed)*100,2) $left = $installed-$inuse $objLabel.Text = "Licenses left: $left/$installed (In use: $percentage%)" $objForm.Refresh()}) $objForm.Controls.Add($RefreshButton) $CloseButton = New-Object System.Windows.Forms.Button $CloseButton.Location = New-Object System.Drawing.Size(150,120) $CloseButton.Size = New-Object System.Drawing.Size(75,23) $CloseButton.Text = "Close" $CloseButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CloseButton) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog()
Thanks