Batch Delete Issued Citrix User/Device Licenses with Udadmin
Udamin.exe
is a handy tool for managing Citrix user/device licenses.
To get a list of currently issued licenses run it like this:
C:\Program Files\Citrix\Licensing\LS>udadmin.exe -list
Usage data is 15 minutes old. Next update in 1 minutes.
Users:
username1 XDT_PLT_UD 2013.0815
username2 XDT_PLT_UD 2013.0815
Devices:
computername1 XDT_PLT_UD 2013.0815
computername2 XDT_PLT_UD 2013.0815
You can delete individual license assignments like this:
udadmin -f FEATURE [-device | -user] NAME -delete
Unfortunately there is no built-in command that deletes all issued licenses. A one-liner batch script adds that missing functionality for device…
for /f "tokens=1,2" %i in ('udadmin -list ^| find /i "_ud"') do @udadmin -f %j -device %i -delete
…and user licenses:
for /f "tokens=1,2" %i in ('udadmin -list ^| find /i "_ud"') do @udadmin -f %j -user %i -delete
If you have both types of licenses, just run both commands one after the other.
16 Comments
Excellent!
Wow…this is most brilliant!!
when i run the above scripts as aprt of batch file. i get the following error:
C:\Program Files (x86)\Citrix\Licensing\LS>Citrixlicense-cleanup3.bat
C:\Program Files (x86)\Citrix\Licensing\LS>cd “C:\Program Files (x86)\Citrix\Lic
ensing\LS”
j was unexpected at this time.
contents of the Citrixlicense-cleanup3.bat as follows:
cd “C:\Program Files (x86)\Citrix\Licensing\LS”
for /f “tokens=1,2” %i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %j -device %i -delete
pause
————–
however if i am in a command prompt and at the following path:
C:\Program Files (x86)\Citrix\Licensing\LS>
running
for /f “tokens=1,2” %i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %j -device %i -delete
and running
for /f “tokens=1,2” %i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %j -user %i -delete
works fine.
so not sure whats happening, please assist
I have the lines in a batch file, and get an error message!
batch file:
cd “C:\Program Files (x86)\Citrix\Licensing\LS”
for /f “tokens=1,2” %i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %j -device %i -delete
pause
error:
C:\Program Files (x86)\Citrix\Licensing\LS>Citrixlicense-cleanup3.bat
C:\Program Files (x86)\Citrix\Licensing\LS>cd “C:\Program Files (x86)\Citrix\Licensing\LS”
j was unexpected at this time.
C:\Program Files (x86)\Citrix\Licensing\LS>for /f “tokens=1,2” j -device i -delete
C:\Program Files (x86)\Citrix\Licensing\LS>
Hi
My licenses keep periodically re-appearing without anyone connecting to the farm when using this method
I’ve also tried deleting the .bin files from the cache folder and restarting the license service with no joy either – same result.
I am using this on a XenApp farm as opposed to XenDesktop, would this make a difference ?
Put this in a batch file if you want it to work;
for /f “tokens=1,2” %%i in (‘.\udadmin.exe -list ^| find /i “_ud”‘) do @udadmin -f %%j -user %%i -delete
You need the .\ in front of the udadmin.exe so it knows its in the current directory, and two %% for the .bat file to get it into the command.
Camo Mike
The “.\” is only required with PowerShell, not with cmd.exe.
The right Batch ist
for /f “tokens=1,2” %%i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %%j -user %%i -delete
Is it possible to run this command with logged-on users?
Yes, users can be logged on while udadmin is run.
Has anyone been able to get this to work..If so, can you tell me how? I tried two variation and cannot get it to work through a batch file….
Variation 1: cd C:\Program Files (x86)\Citrix\Licensing\LS
for /f “tokens=1,2” %i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %j -user %i -delete
error: j was unexpected at this time.
Variation 2:
cd C:\Program Files (x86)\Citrix\Licensing\LS
for /f “tokens=1,2’ %%i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %%j -user %%i -delete
Error: 1 was unexpected at this time
the ultimate goal is to get this to work as a batch file.
In variation 1, you didn’t double the % signs. You always need to double the % signs when putting the command into a batch file.
In variation 2, your quotes don’t match in the beginning. ( “tokens=1,2” not “tokens=1,2′ )
You should use:
for /f “tokens=1,2” %%i in (‘udadmin -list ^| find /i “_UD”‘) do @udadmin -f %%j -device %%i -delete
Here is how i do it using PowerShell
# Script Name: UdadminReset.ps1
# Description: Script to release Citrix licenses
# http://support.citrix.com/proddocs/topic/licensing-1110/lic-admin-cmds-list-deletes-user-device-r.html
#
# Notes:
# 1. This script is scheduled to run thru Windows Task Scheduler
# 2. C:\Program Files (x86)\Citrix\Licensing\LS has been included in the “Path” system variable so udadmin.exe can be called without full path
#=================================================================================================================
#get used licenses
$FilePath = “c:\scripts\output.txt”
udadmin.exe -list -f “XDT_PLT_UD” | Select-String “XDT_PLT_UD 2016.0310” | out-file $FilePath
#remove excess and get license to delete
$Licenses = (Select-String -Pattern “XDT” -Path $FilePath ) | ForEach {$_.line -replace ” XDT_PLT_UD 2016.0310 “,”” }
#$Licenses = (Get-Content $FilePath ) | Select-String -Pattern “XDT” | ForEach {$_.line -replace ” XDT_PLT_UD 2016.0310 “,”” }
#Use udadmin to release licenses
ForEach ($Lic in $Licenses) {
#Write-Host Reset the following user: $Lic
udadmin.exe -f XDT_PLT_UD -user $Lic -delete
}
# restart Licensing service
$svc = (Get-Service -DisplayName “Citrix Licensing”)
Restart-Service -InputObject $svc -verbose
#*********************************************************************
#End Of Script
#*********************************************************************
Exit
Hello Jose,
Are you deleting all kind of licenses with this powershell? Also i do not want to restart the service so i guess i can remove “restart service” part. I tried below script but it did not work.
#get used licenses
$FilePath = “c:\scripts\output.txt”
udadmin.exe -list -f “XDT_ENT_UD” | out-file $FilePath
##Select-String “XDT_ENT_UD 2016.0310”
#remove excess and get license to delete
$Licenses = (Select-String -Pattern “XDT” -Path $FilePath ) | ForEach {$_.line -replace ” XDT_ENT_UD “,”” }
#$Licenses = (Get-Content $FilePath ) | Select-String -Pattern “XDT” | ForEach {$_.line -replace ” XDT_ENT_UD “,”” }
#Use udadmin to release licenses
ForEach ($Lic in $Licenses) {
#Write-Host Reset the following user: $Lic
udadmin.exe -f XDT_ENT_UD -user $Lic -delete
}
# restart Licensing service
#$svc = (Get-Service -DisplayName “Citrix Licensing”)
#Restart-Service -InputObject $svc -verbose
#*********************************************************************
#End Of Script
#*********************************************************************
Exit
This should work with out you having to fill in any variables it will also work out if the license is a user or a computer account meaning it will get everything in one pass and your wont receive errors if it attempts to remove a user that actually a device ect:
$env:Path = “C:\Program Files (x86)\Citrix\Licensing\LS”
$CTXSVC = Get-Service| Where-Object {$_.DisplayName -eq “Citrix Licensing”}
Restart-Service -InputObject $CTXSVC -verbose
$CurrentDate = (Get-Date).ToString(‘MM-dd-yyyy’)
$Logfolder = “c:\scripts”
$Logs = “$Logfolder\Lic.log”
if (!(test-path $Logfolder)){
New-Item -ItemType Directory $Logfolder -Force
}
$used = udadmin.exe -list
$type = “-User”
$feature1 = [regex]::match($used[3],”(?<= )(.*)(?= )").Groups[0].Value
$feature = [regex]::match($feature1, '^([\w\-]+)').Groups[0].Value
foreach ($lic in $used) {
if ($lic -eq "Users:"){
$type = "-User"
}
if ($lic -eq "Devices:"){
$type = "-device"
}
if (($lic -eq $null) -or ($lic -eq "") -or ($lic -eq "Users:") -or ($lic -eq "Devices:") -or ($lic -like "*Usage*")){
}else {
$item = [regex]::match($lic, '^([\w\-]+)').Groups[0].Value
Write-Output "Attempting to remove $item $Type on $CurrentDate" | Out-File $Logs -Append
udadmin -f $feature $type $item -delete | Out-File $Logs -Append
}
}
Restart-Service -InputObject $CTXSVC -verbose
exit
Ready to use. Just copy any *.bat file
for /f “tokens=1,2” %%i in (‘C:\PROGRA~2\Citrix\Licensing\LS\udadmin.exe -list ^| find /i “_ud”‘) do @C:\PROGRA~2\Citrix\Licensing\LS\udadmin.exe -f %%j -user %%i -delete
for /f “tokens=1,2” %%i in (‘C:\PROGRA~2\Citrix\Licensing\LS\udadmin.exe -list ^| find /i “_ud”‘) do @C:\PROGRA~2\Citrix\Licensing\LS\udadmin.exe -f %%j -device %%i -delete