Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <#
  2. Prereqs:
  3. User logged on to domainjoined pc.
  4. Powershell remoting enabled on controller - default on 2012 or later
  5. Service account with permissions to lookup and end session in the Site
  6.  
  7. Script outputs a list of applications that the user had running to a CSV file on the controller - c:\temp\logoff-log.csv.
  8.  
  9. To protect the password of the serviceaccount it would be wise to wrap this into an EXE file.
  10. Place the EXE file on the users desktop og start menu, and they can now stop their sessions.
  11.  
  12. Be aware that the EXE can be reverse engineered - so limit what the service account has access to do.
  13. #>
  14.  
  15. $DeliveryGroupsToSearch = "Deliverygroup_production"
  16. $UsernameToLogoff = $env:USERNAME
  17. $UserDomain = "domain.local"
  18. $Controller = "Controller01.domain.local"
  19. $ControllerUsername = "svc_Xen_logoff"
  20. $ControllerPassword = "SuperSecretPassword" | ConvertTo-SecureString -asPlainText -Force
  21.  
  22. $Credential = New-Object System.Management.Automation.PSCredential($ControllerUsername, $controllerPassword)
  23.  
  24. Invoke-Command -ComputerName $Controller -Credential $Credential -ScriptBlock {
  25. param ($DeliveryGroupsToSearch,
  26. $UsernameToLogoff,
  27. $UserDomain
  28. )
  29. Add-PSSnapin Citrix.Broker.Admin.V2
  30. $ApplicationList = (Get-BrokerSession -Username "$UserDomain\$UsernameToLogoff" -DesktopGroupName $DeliveryGroupsToSearch | Select-Object -ExpandProperty ApplicationsInUse) -join ';'
  31. Get-BrokerSession -Username "$UserDomain\$UsernameToLogoff" -DesktopGroupName $DeliveryGroupsToSearch | Stop-BrokerSession
  32. Add-Content -Path C:\Temp\Logoff-log.csv -Value "$(Get-Date),$UsernameToLogoff,$ApplicationList"
  33. } -ArgumentList $DeliveryGroupsToSearch, $UsernameToLogoff, $UserDomain
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement