Powershell Add-PSSnapin slow in RES Automation Manager

0

When I tried to schedule an simple PowerShell script [See script below], as a module in RES Automation Manager 2012 on a Windows 2008R2 machine, the task took a very long time to finish (+/- 2 min.)

Add-PSSnapin Citrix.XenApp.Commands
$server = get-content env:computername
Disable-XAServerLogOn $server

Note: Script disables the logon to a XenApp server.

When I opened a PowerShell console on the Windows 2008R2 machine and ran the script, I found that the delay was caused by the “Add-PSSnapin” cmd-let. It appears that during this command the Snap-ins has to verify the certificate of the Snap-In online. The User in the security context of the task didn’t has access to the internet and because of this the check times-out and caused the delay.

Solution to this behavior is disabling the certificate check against the Certificate Revocation List. A way to do this is changing the value “State” at [HKCU:\Software\Microsoft\Windows\CurrentVersion \WinTrust\Trust Providers\Software Publishing] to “146944″ (decimal).

I made an other PowerShel task, with the same user in the security context, to modify the above setting in the profile of this user.

set-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing" -name State -value 146944

After this modification of the duration of the task was reduced from +/- 2 min. to 2 a 3 sec.

Delete multiple XenServer orphan SR’s

0

When a Citrix XenServer, member of a Resource Pool, is reinstalled the local storage repositories (Local storage, DVD drive) are left in the resource pool as orphans. In XenCenter, below a Resource Pool, these SR’s are marked with a red bullet.

When there are a few of these orphaned SR, you can remove these with the console command:

xe sr-list

uuid ( RO) : 9901ddd7-6c40-98cf-9ebd-ad381d651ec7
name-label ( RW): DVD drives
name-description ( RW): Physical DVD drives
host ( RO): <not in database>
type ( RO): udev
content-type ( RO): iso

Note uuid of the SR’s with:

host  (RO): <not in database>

To delete this SR:

xe sr-forget uuid=

But what to do if there are to much of the orphaned SR’s ? The procedure above is very time-consuming.

Lets see if Powershell can help solve this problem. For XenServer, as for other Citrix products, are Powershell cmd-lets available. With the help from this Pdf I found the cmd-let to get the SR list.

The command let to get a list of all the SR’s is:

Get-XenServer:SR

I had to find out which property of the SR’s is one of the orphaned SR’s… It appears that an orphaned SR has no PBD’s assigned. Because this property is returned as an array I need a way to determine a way to check this. When an array is empty teh array count is “0″.

Get-XenServer:SR | where-object {$_.PBDs.count -eq 0}

Now we have al the UUID os the orpahned SR’s. To delete a SR in Powershell:

Invoke-XenServer:SR.Forget -SR

Combined in a script, with all the logic and cmd-lets check, will result in:

function checkForPSSnapins ()
{
  Write-Host "-- Verifying PowerShell snapin..."
  #Check if the snapin is installed AND registered properly.
  if(Get-PSSnapin -Name "XenServerPSSnapIn" -Registered -ErrorAction SilentlyContinue){
  #if the snapin is not loaded, load it.
    if (!(Get-PSSnapin "XenServerPSSnapIn" -ErrorAction SilentlyContinue)) {
      Write-Host "-- Loading XenServerPSSnapIn."
      Add-PSSnapin XenServerPSSnapIn
    }
  }
  else{
    Write-Host "-- Citrix XenServerPSSnapIn is not installed/registered on this machine."
    Write-Host "-- Download The XenServer SDK for PowerShell from: http://www.community.citrix.com/cdn/xs/sdks"
    Write-Host "-- Script will now exit."
    exit
  }
}

$POOLMASTER = "FSX-DC1-001"
$USERNAME = "root"
$PASSWORD = "Password"

checkForPSSnapins

Clear-Host

$XS = Connect-XenServer -url http://$POOLMASTER -UserName $USERNAME -Password $PASSWORD

$objSRs = Get-XenServer:SR | Where-Object {$_.PBDs.count -eq 0} | sort-object -Property name_label

ForEach ($objSR in $objSRs)
{
  Write-host $objSR.name_label " " $objSR.uuid
  Invoke-XenServer:SR.Forget -SR $objSR.uuid
}

Res Certified Professional

0

Just received “Res Certified Professional”

RES Baseline Desktop Analyzer Our Experiences

0

an article with my colleague Barry Schiffer.

http://www.barryschiffer.com/?p=396

Next episode:

http://www.barryschiffer.com/?p=440

Xendesktop 5

0

I just past the XenDekstop 5 excam with a score of 84!

Go to Top