<# Read this before proceeding. Log onto the computer you will be performing the Citrix Receiver cleanup using an account with privileged access. Usually a PAE account. Make sure when opening PowerShell ISE, you select the “Run As Administrator” option. Even if you are running with a privileged account you need to “Run As Administrator” for the script to work properly. There is a domain policy that will not allow PowerShell Scripts to run. You must run the following lines at the top of the script before actually running the script. $PSexecutionPolicy = 'Unrestricted' Set-ExecutionPolicy -ExecutionPolicy $PSexecutionPolicy -Force Press the “Play To Run” option from the PowerShell ISE toolbar. This script reboots the computer several times. Keep running the script until the machine stops rebooting. It is very important to complete all stages of the Cleanup Procedure. When the Citrix Cleanup tasks have been complete the following message will be displayed on the screen The Script Has Completed Successfully. Please check the registry HKLM\SOFTWARE\Old Dominion Freight Line\Citrix Build\Receiver Cleanup\Pass Value Should Be 4 Citrix Receiver Cleanup Complete value should be 1 Troubleshooting: If the script fails. Send an eamil to CitrixAlerts@odfl.com with a screenshot of the Receiver Cleanup Registry Values. #> #Set Script Execution Policy $PSexecutionPolicy = 'Unrestricted' Set-ExecutionPolicy -ExecutionPolicy $PSexecutionPolicy -Force # Variables for the Windows Install Script $DesktopImageBuild = "2.0" $DesktopImageBuildDate = get-date -format MM-dd-yyyy $DesktopBuildStartTime = get-date -format "HH:mm:ss" $OSVersion = (Get-WmiObject -class Win32_OperatingSystem).Caption #gets Windows Version Name #Set consitency for begin / end package installations $startinstall = "Installation Begining " $installcomplete = "Installation Completed " $appname = "" # Whatever the application name is - will be written to the registry to confirm installation #Set Installation Media Paths $CitrixCleanupToolPath = "\\corp\itshares\SoftwareRepository\Workstations\Deployed Software\Citrix Receiver\" $CitrixReceiverPath = "\\corp\itshares\SoftwareRepository\Workstations\Deployed Software\Citrix Receiver\" #Set The Root Key For Old Dominion Freight Builds $RegKey = “HKLM:\SOFTWARE\Old Dominion Freight Line\Citrix Build\Receiver Cleanup” $PassValue = “HKLM:\SOFTWARE\Old Dominion Freight Line\Citrix Build\Receiver Cleanup\Pass Value” #check to see if the $regkey value exists - if not - write the value if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } function Invoke-VDACleanupPassOne() { Begin { $appName = "Cleanup Performed By" Write-Host $startInstall$appName + $env:username if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appname -Type String -Value $env:username Write-Host $installcomplete$appname + $env:username $appName = "Cleanup Date" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopImageBuildDate Write-Host $installcomplete$appname $appName = "Cleanup Start Time" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname } Process{ $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Initiate Receiver Cleanup Pass One" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Receiver Cleanup Tool Pass One" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Value "0" Start-Process -Wait "$CitrixCleanupToolPath\ReceiverCleanupUtility.exe" /silent Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value "1" Write-Host $installcomplete$appname #Initiate Machine Reboot $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Initiate System Reboot Pass One" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Pass Value" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appname -Type String -Value "1" Write-Host "simulate machine reboot pass one" # restart-computer -Force } End{} } # Pass One Citrix Receiver Cleanup Tool Complete # Pass Two Citrix Receiver Cleanup Tool - Begin function Invoke-VDACleanupPassTwo() { Begin { <# #> } Process{ $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Initiate Receiver Cleanup Pass Two" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Receiver Cleanup Tool Pass Two" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Value “0” Start-Process -Wait "$CitrixCleanupToolPath\ReceiverCleanupUtility.exe" /silent Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value "1" Write-Host $installcomplete$appname #Initiate Machine Reboot $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Initiate System Reboot Pass Two" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Pass Value" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appname -Type String -Value "2" Write-Host "simulate machine reboot pass two" # restart-computer -Force } End{} } # Pass Two Citrix Receiver Installation Begin function Invoke-VDACleanupPassThree() { Begin { <# #> } Process{ $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Citrix Receiver Install Pass One" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Citrix Receiver Install Pass One" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value 0 Start-Process -Wait "$CitrixCleanupToolPath\Receiver 4.9.5000 for Windows- LTSR Cumulative Update 5.exe" /silent Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value "1" Write-Host $installcomplete$appname #Initiate Machine Reboot $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Initiate System Reboot Pass Three" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Pass Value" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appname -Type String -Value "3" Write-Host "simulate machine reboot pass three" #restart-computer -Force } End{} } #Initiate Cleanup After Script has been run function Invoke-VDACleanupPassFour() { Begin { <# #> $appName = "Cleanup End Time" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname } Process{ $DesktopBuildStartTime = get-date -format "HH:mm:ss" $appName = "Citrix Receiver Install Pass Two" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appName -Type String -Value $DesktopBuildStartTime Write-Host $installcomplete$appname $appName = "Citrix Receiver Cleanup Complete" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } #Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value “0” Set-ItemProperty -Path “$RegKey” -Name $appName -Type string -Value "1" Write-Host $installcomplete$appname #Finalize Cleanup $appName = "Pass Value" Write-Host $startInstall$appName if (-Not(Test-Path “$RegKey”)) { New-Item -Path “$($RegKey.TrimEnd($RegKey.Split(‘\’)[-1]))” -Name “$($RegKey.Split(‘\’)[-1])” -Force | Out-Null } Set-ItemProperty -Path “$RegKey” -Name $appname -Type String -Value "4" #Set Script Execution Policy $PSexecutionPolicy = 'Restricted' Set-ExecutionPolicy -ExecutionPolicy $PSexecutionPolicy -Force Clear Write-Host "The Script Has Completed Successfully. Please check the registry HKLM\SOFTWARE\Old Dominion Freight Line\Citrix Build\Receiver Cleanup\Pass Value Should Be 4 Citrix Receiver Cleanup Complete value should be 1" } End{} } $PassValue = (Get-ItemProperty -path $RegKey -name "Pass Value")."Pass Value" Switch ($PassValue) { "" {Invoke-VDACleanupPassOne ; break} "1" {Invoke-VDACleanupPassTwo ; break} "2" {Invoke-VDACleanupPassThree ; break} "3" {Invoke-VDACleanupPassFour ; break} default {"None of the Above"; break} }