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.

, ,

14 Responses to Batch Delete Issued Citrix User/Device Licenses with Udadmin

  1. Marco December 18, 2012 at 10:22 #

    Excellent!

  2. LK March 6, 2013 at 19:18 #

    Wow…this is most brilliant!!

  3. mr rosh August 12, 2013 at 06:14 #

    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

  4. mr rosh August 14, 2013 at 01:09 #

    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>

  5. Paul August 21, 2013 at 14:43 #

    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 ?

  6. Camo MIke January 27, 2014 at 19:56 #

    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

    • Helge Klein January 29, 2014 at 13:56 #

      The “.\” is only required with PowerShell, not with cmd.exe.

  7. markus February 5, 2014 at 14:13 #

    The right Batch ist

    for /f “tokens=1,2” %%i in (‘udadmin -list ^| find /i “_ud”‘) do @udadmin -f %%j -user %%i -delete

  8. Hello February 2, 2015 at 14:44 #

    Is it possible to run this command with logged-on users?

    • Helge Klein February 2, 2015 at 14:49 #

      Yes, users can be logged on while udadmin is run.

  9. mr March 9, 2015 at 21:15 #

    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.

    • Jesse March 30, 2015 at 22:46 #

      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

  10. Jose July 23, 2015 at 14:05 #

    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

  11. satya September 17, 2015 at 21:32 #

    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

Leave a Reply