Last active
June 19, 2020 10:00
-
-
Save raulunzue/a186acb004e020f9f73aa238d86a8661 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 | |
$sesiones=Get-BrokerSession | Select-Object Username | Set-Content C:\Scripts\Usuario.txt | |
# Limpiamos los espacios en blanco | |
(gc C:\Scripts\Usuario.txt) | ? {$_.trim() -ne "" } | Set-Content C:\Scripts\Usuario.txt | |
(gc C:\Scripts\Usuario.txt) -replace ("@{UserName=", "") -replace ("}", "") | Set-Content C:\Scripts\Usuario.txt | |
(gc C:\Scripts\Usuario.txt) | ? {$_.trim() -ne "" } | Set-Content C:\Scripts\Usuario.txt | |
$Existe=(gc C:\Scripts\Usuario.txt) | |
#Cerramos todas las sesiones de los usuarios detectadas | |
If ($Existe) | |
{ | |
ForEach ($user in $(Get-Content C:\Scripts\Usuario.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" | |
} | |
Remove-Item C:\Scripts\Usuario.txt |
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/