Thursday, February 23, 2012

Cosonok's IT Blog: Citrix Udadmin Delete Script & Event 1163

Cosonok's IT Blog: Citrix Udadmin Delete Script & Event 1163:

Citrix Udadmin Delete Script & Event 1163

Scenario:

Users are unable to logon to their Citrix XenDesktop 5 desktops, and the following error is seen in the Windows Application log on the XenDesktop 5 Controller:
Event 1163, Citrix Broker Service : No connection license available. To resolve, free licenses by closing sessions that are not needed, or add more licenses.”

Solution to free one license at a time:

i: Logon to the Citrix Licensing server and open up a command prompt.
ii: Run the command below to 'list all licensed users and devices organized by feature and version':

udadmin -list -a

iii: Then run either the first command below to 'delete a licensed user from the feature specified' or the second command below to 'delete a licensed device from the feature specified' (Note that … -device … -delete did not work until Citrix License Server Version 11.9 Build #11011.)

udadmin -f featurename -user username -delete
udadmin -f featurename -device devicename -delete

Solution to free multiple licenses at a time:

i: From a command prompt run the command

udadmin -list -a > users.txt

ii: Edit the users.txt file to contain just the user strings (users or devices) as desired (don't worry about preceding spaces,) remembering to note the feature name from the output.
iii: (If required) Edit strFeature string in udadmindelete.vbs script if different from XDT_ENT_UD.
iv: (If required) Change strUserDev string in udadmindelete.vbs script from user to device if running against a list of devices.
v: Double-click on the udadmindelete.vbs script to run (the users.txt file needs to be in the same location as the udadmindelete.vbs script.)

And we're done!

udadmindelete.vbs script:

Copy all the contents below into a text document and save as udadmindelete.vbs.
Remember to change the string contents for strFeature and strUserDev (user or device) as per requirements.
Apologies if this is not the most elegant script, was a mash up of bits and pieces from around the net!

Option Explicit
Dim objFSO, strTextFile, strData, strLine, arrLines, objShell, strTmp, strFeature, strUserDev
CONST ForReading = 1
set objShell = wscript.createObject("wscript.shell")

'Name of the text file to be read
strTextFile = "users.txt"

'ADJUST strFeature AS PER REQUIREMENTS
strFeature = "XDT_ENT_UD"

'ADJUST strUserDev AS PER REQUIREMENTS
strUserDev = "user"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
strTmp = "udadmin -f " & strFeature & " -" & strUserDev & " " & strLine & " -delete"
'To see the command being, run add a line below with wscript.echo strtmp
objShell.Run strTmp
Next

'Cleanup
Set objFSO = Nothing


Wednesday, February 15, 2012

PowerShell Script for Exporting a virtual machine

PowerShell Script for Exporting a virtual machine:

Even though it might be tempting just to copy a whole virtual machine from Hyper-V Host to Hyper-V Host, this is not the way to do it. Importing and Exporting Hyper-V-style is. This post provides a PowerShell script to make it easier.


I need to automate the process of exporting a virtual machine recently – and when I checked around I found that while there are a number of sample scripts out there that show you how to do this (some even on this blog) they are all written in VBScript. As I am now to the stage where PowerShell is my preferred scripting language – I sat down and wrote up this short script:

# Function for handling WMI jobs / return values

Function ProcessResult($result, $successString, $failureString)

{

   #Return success if the return value is "0"

   if ($result.ReturnValue -eq 0)

      {write-host $successString} 

 

   #If the return value is not "0" or "4096" then the operation failed

   ElseIf ($result.ReturnValue -ne 4096)

      {write-host $failureString " Error value:" $result.ReturnValue}

 

   Else

      {#Get the job object

      $job=[WMI]$result.job

 

      #Provide updates if the jobstate is "3" (starting) or "4" (running)

      while ($job.JobState -eq 3 -or $job.JobState -eq 4)

         {write-host $job.PercentComplete "% complete"

          start-sleep 1

 

          #Refresh the job object

          $job=[WMI]$result.job}

 

       #A jobstate of "7" means success

       if ($job.JobState -eq 7)

          {write-host $successString

          return $true}

       Else

          {write-host $failureString

          write-host "ErrorCode:" $job.ErrorCode

          write-host "ErrorDescription" $job.ErrorDescription

          return $false}

       }

}

 

# Prompt for the Hyper-V Server to use

$HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"

 

# Prompt for the virtual machine to use

$VMName = Read-Host "Specify the name of the virtual machine"

 

# Prompt for the path to export to

$ExportPath = Read-Host "Specify the path to place the exported virtual in"

 

# Get the management service

$VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer

 

# Get the virtual machine object

$VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer

 

# Export the virtual machine

$result = $VMMS.ExportVirtualSystem($VM, $true, $ExportPath)

 

# Check to make sure we succeeded

$exportSucceeded = ProcessResult $result "Virtual machine exported." "Failed to export virtual machine."

Some quick notes to make about this script:


  • This script takes a Hyper-V server name, a virtual machine name and an export path – and then performs a full export to the requested location.

  • I am using the older (deprecated) ExportVirtualSystem method here – and not ExportVirtualSystemEx (which I really should do). The main reason for this is that while ExportVirtualSystemEx is a lot more powerful than ExportVirtualSystem, ExportVirtualSystem works perfectly fine for this basic use case and is much easier to script.

Source and download: http://blogs.msdn.com/b/virtual_pc_guy/archive/2012/02/08/powershell-script-for-exporting-a-virtual-machine.aspx

Similar Posts:



FREE Tool: NTFS Permissions Reporter – What are the NTFS permissions?

FREE Tool: NTFS Permissions Reporter – What are the NTFS permissions?:

NTFS Permissions Reporter is a new tool from Cjwdev, with a completely free edition available for anyone to download and use without any registration or time limits imposed. It makes auditing and reviewing permissions on your file system quick and easy.



you can simply right click on any directory in Windows Explorer and choose Report Permissions to launch the program and instantly see how permissions are assigned to that directory and all of its sub directories.


What are the NTFS permissions - NTFS Permissions Reporter


What are the NTFS permissions? NTFS Permissions Reporter




The report results can be viewed in either tree format (which mimics the explorer style view of directories that we are all used to) or in a sortable table format. Different levels of permissions are highlighted in different colours to make it easy to see at a glance what level of access a particular user or group has to a directory.


Source and download: http://4sysops.com/archives/free-ntfs-permissions-reporter-what-are-the-ntfs-permissions/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+4sysops+%284sysops%29


Similar Posts:





Tuesday, February 7, 2012

How to Clear DNS Cache in Mac OSX Leopard

dscacheutil -flushcache  

ThinKiosk - Turn Your Old Hardware into a Windows Thin Device for Free!

Chris Keim did a great write up about ThinKiosk.

ThinKiosk - Turn Your Old Hardware into a Windows Thin Device for Free!: During all my VDI roll-outs, at the end of building the infrastructure and training the customer with client deployment techniques, there is always the question on how to make create the best endpoint experience for the user. There are several different ways of course, depending on what functionality the end user needs. But, in regards to your basic task worker, where all they need is a connection to their virtual desktop, and they want to utilize their current endpoint devices, I usually would recommend a home brew solution that I created. My solution involved setting up Internet Explorer in kiosk mode and setting that to the user interface instead of explorer.exe and a list of registry/group policy modifications that limits what the end user can do on their endpoint and give them access to their virtual desktop. My solution was OK at best for customers who wanted a free solution and did not want to go the Linux route as this had several disadvantages as well.

Now, some very smart person named Andrew Morgan created an application that is meant to replace the default shell explorer.exe This new shell brings the user straight to the Citrix Web Interface for login to access their virtual desktop. The reasons why I am very impressed with this shell:

  • Session and power state control
    • Restart
    • Shutdown
    • Log off
  • User session options
    • Display settings
    • Keyboard settings
    • Mouse settings
    • Volume settings
  • Administrator options
This gives users the basic control necessary for a positive end user experience, without giving them unneeded access. A nice feature what feature is displayed to the user either by Group Policy or registry editing. Below is how I setup ThinKiosk:

  1. Created a new VM to gain a better vantage of a typical customer aging endpoint device:
    1. Windows XP x86
    2. 512MB RAM
    3. 10GB hard drive
  2. After I logged into the VM for the first time, I installed the following:
    1. Internet Explorer 8
    2. Adobe Flash Player
    3. Citrix Receiver
    4. ThinKiosk
  3. Create a user and set that user to auto login:
    1. In a command prompt type "Control userpasswords2"
    2. Complete the autologin configuration
  4. I then modified the shell for the auto login user account to point to ThinKiosk.exe:
    1. Navigate to HKCU\Software\Microsoft\WindowsNT\CurrentVersion\Winlogon
    2. Created a new string named "Shell"
    3. Set the data value to "C:\Program Files\ThinKiosk\ThinKiosk.exe"
    4. You can also set this through Group Policy - http://technet.microsoft.com/en-us/library/cc975911.aspx
  5. Created the following registry keys (you can create these through Group Policy preferences):
    1. Create the following key: HKCU\Software\ThinKiosk
    2. Create the following values:
      1. Name = "URL"
        1. Type = REG_SZ
        2. Value = the URL to your Citrix Web Interface
      2. Name = "SHOWADMINMENU"
        1. Type = REG_DWORD
        2. Value = 1 or 0
      3. Name = "SHOWLOGOFF"
        1. Type = REG_DWORD
        2. Value = 1 or 0
      4. Name = "WINDOWMODE"
        1. Type = REG_DWORD
        2. Value = 1 or 0
      5. Name = "WINDOWMODEPERCENT"
        1. Type = REG_SZ
        2. Value = 1 or 0
    3. The above settings can also be made through group policy, in which there is an ADM file that you can download from the ThinKiosk site
  6. Configure the following group policy settings:
    1. Local Computer Policy\User Configuration\Administrative Templates\System\Ctrl+Alt+Del Options
      1. Remove change password - Enabled
      2. Remote lock computer - Enabled
      3. Remote task manager - Enabled