Jump to content
Updated Privacy Statement
  • 6

Powershell Script repository.

Randy White1709153608


I've looked for a script repository on here or a common place that people post scripts they have created and I havent had much luck. So I thought I would start a thread and see where it goes from there. Use the scripts in this thread with caution and ask questions if your not familiar with Powershell.


Also I should have mentioned that if you see something wrong with any of these scripts or maybe a better way of doing something please feel free to give suggestions. 

  • Like 4
Link to comment
  • Answers 58
  • Created
  • Last Reply

Top Posters For This Question

Recommended Posts

  • 0
On 1/30/2019 at 2:30 PM, Jason Medlin1709157423 said:

I wrote a GUI Based Support Tool that views sessions with the ability to connect in via remote assistance and log the session off.  I also uploaded it to TechNet: https://gallery.technet.microsoft.com/Citrix-IT-Support-Tool-46d9d59d?redir=0



Citrix_Support_Tool_V1_1.ps1 16.83 kB · 13 downloads

Support Tool Manual v1.1.pdf 417.49 kB · 25 downloads


Nicely done Jason.  I slightly tweaked your script however.  Typically we'd run this directly from the Controller / Director / StoreFront server (most of our sites are smaller with only a single controller that does it all).  So now rather than have to update the script for each client location, it automatically uses the machine's FQDN and the logged in user's Netbios Domain name for it's connection.  I also defined the default Web Browser, and the URL to the Director based on the machine's FQDN.

### Add Modules ###
Import-Module ActiveDirectory
asnp Citrix.Broker.Admin.V2
$DNSDomainName = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
$DNSDomainName = $DNSDomainName.ToLower()
$ThisComputersFQDN = $env:computername + "." + $DNSDomainName
$ThisComputersFQDN = $ThisComputersFQDN.ToLower()
$UserDomain = $env:userdomain + "\"

$Browser = "C:\Program Files\Mozilla Firefox\firefox.exe"
$Director = " https://" + $ThisComputersFQDN + "/Director"

function OnApplicationLoad {
    return $true #return true for success or false for failure

function OnApplicationExit {
    $script:ExitCode = 0 #Set the exit code for the Packager

$separator = "\"
$DDC = $ThisComputersFQDN.ToLower()
###Enter Name or IP of Controller###
$Logfile = "c:\windows\temp\Citrix_Tool_Log.txt"
###Set your Log File Location###
$AD_Domain = $UserDomain
###Add your Domain

I also updated button 1 to use my variables ($Browser $Director) instead of the hard coded Firefox link you had there:

    $SC1_Button.enabled = $False
    & $Browser $Director
    Start-Sleep -Seconds 2
    $SC1_Button.enabled = $True

Finally - I utilized PS2EXE-GUI to convert the PowerShell script to an .exe, digitally signed it with my GoDaddy code signing certificate, rolled out to all our controllers, and created desktop shortcuts.





Link to comment
  • 0
On 11/10/2017 at 2:08 AM, Kevin Dreyer said:

I use the following pshell command to get ClientMachine Name and IP.

Get-WmiObject -Namespace root\Citrix\euem -Class citrix_euem_clientConnect


Hi there,

Would you be able to then take the clientmachinename of a specific logged on user to edit a file in their profile and enter the hostname in the file for licensing purposes?

Link to comment
  • 0
On 6/20/2017 at 6:01 AM, Randy White1709153608 said:

Clears Write Cache. I have this set to a logoff action to clean up the write cache if I no longer store event logs there or if I'm done troubleshooting a problem. 


$writecache= (Get-WMIObject Win32_Volume | ? { $_.Label -eq 'WCDisk'-or $_.Label -eq "WRcache" } |select name).name
$driveletter = test-path $writecache
if($driveletter -eq $true)
Remove-Item -path $writecache\'$RECYCLE.BIN' -Recurse -force

Hi Randy. 


Does this script clear WriteChe of cache type "Cache on Decice RAM then overflow to Disk" on Windows 10 VDIs and Windows 2012/2016  XenApp servers.  In our environment, WriteCache drive also holds page file, Windows event logs and other product logs..


Thanks for your scripts.




Link to comment
  • 0
17 hours ago, J Kamberi said:

hello all

i am looking for a way to show all active user sessions in prtg.

does anyone have a powershell script i can run, and if so, on what components to run it?


thank you very much, i am quite new in citrix business


Get-BrokerSession -SessionState Active -MaxRecordCount 200000 | Format-Table -AutoSize


Try above PS Command 

Link to comment
  • 0
On 3/29/2023 at 3:41 PM, J Kamberi said:

hello all

i am looking for a way to show all active user sessions in prtg.

does anyone have a powershell script i can run, and if so, on what components to run it?


thank you very much, i am quite new in citrix business

Hi, there is a githubscript that bring to PRTG active sessions and much more: PRTG-CitrixFarmScript/citrixFarmPRTG.ps1 at master · Teagan-Wilson/PRTG-CitrixFarmScript · GitHub

I've extended with checks worker in maintenance mode and in "unknow" powerstate:


#Teagan Wilson

param (

#Build the creds that get passwed from PRTG
$credentials = New-Object System.Management.Automation.PSCredential (($domain+'\'+$username), (ConvertTo-SecureString $password -AsPlainText -Force))

#Generate Script Block to run remotly on Citrix Farm Broker
$job = Invoke-Command -Computername $server -credential $credentials -ScriptBlock { 

#Load Citrix Powershell Modules (remotely on the Farm Broker)
add-pssnapin citrix*; 

#Get Active Citrix Active/Not Active Session Numbers
$ActiveSessions = (Get-BrokerSession | where {$_.SessionState -eq "Active"}).Count
#$DisconnectedSessions = (Get-BrokerSession | where {$_.SessionState -ne "Active"}).Count

#Get Worker in Maintenance mode
$InMaintenance = (Get-BrokerMachine | where {$_.InMaintenanceMode -eq "True"}).Count

#Get Worker in Power state "Unknow"
$PowerState = (Get-BrokerMachine | where {$_.PowerState -eq "Unknow"}).Count

#Get Broker controller Active
$BrokerController = (Get-BrokerController | where {$_.State -eq "Active"}).Count

#Get Broker Status - Convert 'OK' or not to numeric 1 or 0
$BrokerStatus = if(((Get-BrokerServiceStatus).ServiceStatus -eq 'OK')) {1} else {0}

#Create Object with above information so we can pass it back out later. 
$Data= [PSCustomObject]@{
BrokerStatus = $BrokerStatus
BrokerController = $BrokerController
Worker_In_Maintenance = $InMaintenance
Power_State_Unknow = $PowerState
ActiveSessions = $ActiveSessions
#DisconnectedSessions = $DisconnectedSessions

#Get Session Information for each VDA in the farm add it to the custom object as another channel.
$servers = Get-BrokerMachine | Select MAchineName
ForEach ($machine in $servers)
$serversessions = (Get-BrokerSession | where {($_.SessionState -eq "Active") -and ($_.MachineName -eq $machine.MachineName)}).Count
$Data | Add-Member -MemberType NoteProperty -Name ('sessions-'+$machine.MachineName) -Value $serversessions

#Return Farm info
return $Data

} -asjob

#Wait for the job to finish and get the data
Wait-Job $job | Out-Null
$Data= Receive-Job -Job $job

#Build our XML object to output for PRTG
$returntext = '<prtg>' 
$Data.PSObject.Properties | foreach-object {
$returntext += '<result><channel>'+$_.Name+'</channel><value>'+$_.Value+'</value></result>'
$returntext = $returntext -replace " ",""
$returntext += '</prtg>'

write-host $returntext

#Below for debug
#$returntext | Out-File C:\ProgramData\citrixfarmscript-output.txt
exit 0

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...