Last active
June 19, 2020 10:01
-
-
Save raulunzue/2fb78a4b5dd450a2863939308dd92445 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
# Cargamos modulo | |
Add-PSSnapin Citrix.Broker.Admin.V2 | |
# Obtenemos las sesiones | |
(Get-BrokerSession | Select-Object -Property BrokeringUserName | Format-Wide -Column 1 | Out-String) | Set-Content C:\Scripts\Usuario.txt | |
# Limpiamos los espacios en blanco | |
(gc C:\Scripts\Usuarios.txt) | ? {$_.trim() -ne "" } | Set-Content C:\Scripts\Usuarios.txt | |
$Existe=C:\Scripts\Usuarios.txt | |
#Cerramos todas las sesiones de los usuarios detectadas | |
If ($Existe -eq $True) | |
{ | |
ForEach ($user in $(Get-Content C:\Scripts\Usuarios.txt)) | |
{ | |
# Generamos log | |
$date= Get-Date | |
#$log = Write-Output "$date, Forzamos cierre sesion de $user" | |
Add-Content "$date, Forzamos cierre sesion de $user" -Path "C:\Scripts\sesiones-cerradas.log" | |
Get-BrokerSession -Username $user | Stop-BrokerSession | |
} | |
} | |
Else | |
{ | |
# Generamos log | |
$date= Get-Date | |
$log = Write-Output "$date, No hay sesiones que cerrar" | |
Add-Content $log -Path "C:\Scripts\sesiones-cerradas.log" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.maquinasvirtuales.eu/citrix-script-cerrar-sesiones/