Last active
July 25, 2020 22:17
-
-
Save raulunzue/94eff02019b5089182fab573e9ede680 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuramos Variables | |
$Total = 0 | |
$Usadas = 0 | |
$PorcentajeUso = 0 | |
$ReturnString = 0 | |
$ReturnValor = 0 | |
# Obtendremos los datos mediante WMI | |
$licensePool = gwmi -class "Citrix_GT_License_Pool" -Namespace "ROOT\CitrixLicensing" -comp SRVLICENCIAS | |
# Devuelve todas las licencias | |
$licensePool | Select-Object @{n="Producto";e={$_.PLD}}, | |
@{n="Instaladas";e={$_.Count}}, | |
@{n="En Uso";e={$_.InUseCount}}, | |
@{n="Disponibles";e={$_.PooledAvailable}}, | |
@{n="% en Uso";e={($_.InUseCount/$_.Count)*100}} | |
# Si tienes licencias MPS_ENT_CCU. Utilizaríamos para calcularlas lo siguiente: | |
#$LicensePool | ForEach-Object{ If ($_.PLD -eq "MPS_ENT_CCU"){ | |
#$Total = $Total + $_.count | |
#$Usadas = $Usadas + $_.InUseCount | |
#} | |
#} | |
# Descomentar para confirmar que los valores son correctos | |
#"Total = ", $Total | |
#"En Uso = ", $Usadas | |
$PorcentajeUso = [Math]::Round($Total*100,0/$Usadas) | |
# Determinamos el código de retorno. Si tiene menos del 90%, OK, 90-97 Warning, 98-100 Error | |
switch ($PorcentajeUso) | |
{ | |
{$PorcentajeUso -lt 90} { | |
$ReturnString = "OK, estamos por debajo del umbral del 90% de Uso" | |
$ReturnValor = 0 | |
break | |
} | |
{$PorcentajeUso -ge 90 -and $PorcentajeUso -lt 98} { | |
$ReturnString = "WARNING: 90-97% Licencias en Uso" | |
$ReturnValor = 1 | |
break | |
} | |
{$PorcentajeUso -ge 98} { | |
$ReturnString = "ALERTA: 98-100% Licencias en Uso" | |
$ReturnValor = 2 | |
} | |
} | |
# Pintamos los valores | |
Write-Host $ReturnString | |
exit $ReturnValor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment