-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cleanup.ps1
16 lines (14 loc) · 1.03 KB
/
Cleanup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#Enter the name of your Desktop Delivery Controller below.
#If you have Load Balanced your Desktop Delivery Controllers, use that address instead.
$DDC = "Delivery Control.FQDN.HERE"
#Do not modify any of the below code unless you know what you are doing.
$username = $args[0]
$group =$args[1]
$PublishedApp = $args[2]
$DeleteTimeCode = Get-Date -Format "yyyy-MM-dd'T'HH:mm:ss"
Remove-ADGroupMember -Identity $group -Members $username -Confirm:$false
Invoke-Command -ComputerName $DDC -ScriptBlock{get-brokersession | where-object ApplicationsInUse -eq "$using:PublishedApp" | where-object Username -CLike "*\$using:username" | Stop-Brokersession }
#Generate a Logfile entry for when user is removed from AD, and Published Application is logged off.
$LoggingFile = ".\logs\SecureLog" + (Get-Date -Format "yyyy-MM-dd")
$Logging = "User " + $username + " was removed from " + $group + " Active Directory Group at " + $DeleteTimeCode + " and published application " + $PublishedApp + " was signed out."
$Logging | Out-File -FilePath $LoggingFile -Append