Documenting a Citrix Provisioning Services Farm with Microsoft PowerShell

April 13, 2012

PowerShell, PVS

A customer site I was at recently needed their Provisioning Services (PVS) farm documented. Since I had already created PowerShell scripts to document the various versions of XenApp, I figured a PVS script should be easy to create. I could not have been more wrong in my thinking! This article and script were written on and tested against PVS 5.6 SP2, 6.0 and 6.1 all running on Microsoft Windows Server 2008 R2 SP1.

NOTE: This script is continually updated.  You can always find the most current version by going to http://carlwebster.com/where-to-get-copies-of-the-documentation-scripts/

I would recommend downloading the Citrix PVS PowerShell Programmer’s Guide for the version of PVS for your Farm. While most of each guide is the same, each guide is specific to each version of PVS. For example, the PVS 6.1 guide has information on the new Personal vDisk that is only supported in PVS 6.1.

Citrix Provisioning Services 5.6 SP1 PowerShell Programmer’s Guide

Citrix Provisioning Services 6.0 PowerShell Programmer’s Guide

Citrix Provisioning Services 6.1 PowerShell Programmer’s Guide

My initial goal was to see if I could walk down the nodes in the Provisioning Services Console (PSC) and see if I could document every nook and cranny. PVS 5.6 SP2 is shown in Figure 1 and PVS 6.1 is shown in Figure 2.

Figure 1

Figure 2

Before we can start using PowerShell to document anything in the PVS farm we first need to register the PVS Console PowerShell snap-in. Even if you are running PVS on a 64-bit Windows Server Operating System you must still register the snap-in with the 32-bit .Net Framework.

Change to the folder where the PSC is installed. By default, this is C:\Program Files\Citrix\Provisioning Services Console.

To register with the 32-bit .Net Framework, enter the following command (Figure 3):

%systemroot%\Microsoft.NET\Framework\v2.0.50727\installutil.exe McliPSSnapIn.dll

Figure 3

To register with the 64-bit .Net Framework, enter the following command (Figure 4):

%systemroot%\Microsoft.NET\Framework64\v2.0.50727\installutil.exe McliPSSnapIn.dll

Figure 4

Click Start, Administrative Tools, Windows PowerShell Modules. A PowerShell session starts. Enter the following command:

Add-PSSnapin –Name McliPSSnapIn

Everything is now setup for us to get started.

PowerShell commands are supposed to be done in a Verb-Noun format. Get-Something, New-Something, Copy-Something, etc. That is the way Citrix did the PowerShell commands for XenApp 5, XenApp 6.x and XenDesktop 4. But that is not what Citrix did for PVS.

In XenApp or XenDesktop 4, if I wanted to retrieve farm information I would use Get-XAFarm or Get-XDFarm. I thought the obvious thing to do was to use Get-PVSFarm but that doesn’t work. For some bizarre reason, Citrix decided to wrap PowerShell around the PVS MCLI command line utilities.

I could write an article on all the things Citrix did wrong with their PVS PowerShell implementation but that would not serve any useful purpose. This article will do its best to stay focused on what is needed to use what Citrix gave us to document a PVS farm.

To get a list of the MCLI commands, showing just the Name, where the “verb” starts with “mcli”, type the following in the PowerShell session (results are shown in Figure 11):

Get-Command -Verb mcli | Select-Object Name

Figure 5

, ,

About Carl Webster

Webster is a Sr. Solutions Architect for Choice Solutions, LLC and specializes in Citrix, Active Directory and Technical Documentation. Webster has been working with Citrix products for many years starting with Multi-User OS/2 in 1990.

View all posts by Carl Webster

8 Responses to “Documenting a Citrix Provisioning Services Farm with Microsoft PowerShell”

  1. Jimmy Says:

    Carl,

    First of all, thanks for making available such useful information. I am looking for a copy of the ‘Citrix Provisioning Services 6.1 PowerShell Programmer’s Guide’. It is nowhere to be found. Would you happen to have a copy laying around? Thanks

    Reply

  2. Thomas Schläppi Says:

    Hi Carl

    I’m using the function BuildPVSObject, but i get some strange results:

    $GetWhat = “collection”
    $GetParam = “siteName=MySite,collectionName=MyCollection”
    $ErrorTxt = “PVS collection information”
    $Result = BuildPVSObject $GetWhat $GetParam $ErrorTxt

    then i get the following error:
    Mcli-Get : The specified Site does not exist.

    $GetParam = “siteName=MySite” works korrectly…

    Seems to be a strange behaviour, when i print out the full mcli command:

    If($MCLIGetParameters -ne ”)
    {
    $MCLIGetResult = Mcli-Get “$($MCLIGetWhat)” -p “$($MCLIGetParameters)”
    Write-Host “Mcli-Get $($MCLIGetWhat) -p $($MCLIGetParameters)”
    }
    …and run the printed code in a powershell window, it works.

    Have you any idea, what the cause of this error is?

    Thomas

    Reply

    • Carl Webster Says:

      This is one of the stupid things with the current PVS PoSH implementation. You are passing two parameters in a string which is interpreted as an array. When I needed to pass two, or more, parameters, I could not use the BuildPVSObject function.

      For example:

      #cannot use the BuildPVSObject Function here
      $serverbootstraps = @()
      ForEach($Bootstrapname in $Bootstrapnames)
      {
      #get serverbootstrap info
      $error.Clear()
      $tempserverbootstrap = Mcli-Get ServerBootstrap -p name=”$($Bootstrapname.name)”,servername=”$($server.serverName)”
      If($error.Count -eq 0)
      {
      $serverbootstrap = $Null
      ForEach($record in $tempserverbootstrap)
      {
      If($record.length -gt 5 -and $record.substring(0,6) -eq “Record”)
      {
      If($serverbootstrap -ne $Null)
      {
      $serverbootstraps += $serverbootstrap
      }
      $serverbootstrap = new-object System.Object
      #add the bootstrapname name value to the serverbootstrap object
      $property = “BootstrapName”
      $value = $Bootstrapname.name
      Add-Member -inputObject $serverbootstrap -MemberType NoteProperty -Name $property -Value $value
      }
      $index = $record.IndexOf(‘:’)
      If($index -gt 0)
      {
      $property = $record.SubString(0, $index)
      $value = $record.SubString($index + 2)
      If($property -ne “Executing”)
      {
      Add-Member -inputObject $serverbootstrap -MemberType NoteProperty -Name $property -Value $value
      }
      }
      }
      $serverbootstraps += $serverbootstrap
      }
      Else
      {
      WriteWordLine 0 0 “Server Bootstrap information could not be retrieved”
      WriteWordLine 0 0 “Error returned is ” $error[0].FullyQualifiedErrorId.Split(‘,’)[0].Trim()
      }
      }

      Hope this helps and I really can’t wait for PVS 7.7 and the new REAL PowerShell implementation.

      Webster

      Reply

      • Roger Hart Says:

        Thanks for these great scripts! I was able to modify the BuildPVSObject function to take multiple parameters using this code:

        If($MCLIGetParameters -ne ”)
        {
        # split multiple params into an array
        $ArrGetParams=$MCLIGetParameters.Split(‘,’)
        # pass the array to Mcli-get
        $MCLIGetResult = Mcli-Get “$($MCLIGetWhat)” -p ($ArrGetParams)
        }
        Else
        {
        $MCLIGetResult = Mcli-Get “$($MCLIGetWhat)”
        }

        It’s working so far in my limited testing. The remainder of the function code is unaffected.

  3. Frank Says:

    Good Morning Carl. I’m running the PVS script on my PVS server. Is there a way to run the script with out installing word on my PVS server? The following is the message I receive.

    PS C:\scripts> .\PVS_Inventory.ps1 |out-file .\PVSFarm.txt
    VERBOSE: 02/25/2015 07:32:27: Testing output parameters
    VERBOSE: 02/25/2015 07:32:27: MSWord is set
    VERBOSE: 02/25/2015 07:32:27: CoName is
    VERBOSE: 02/25/2015 07:32:27: Checking for McliPSSnapin
    VERBOSE: 02/25/2015 07:32:28: Verifying PVS SOAP and Stream Services are running
    VERBOSE: 02/25/2015 07:32:28: Getting PVS version info
    VERBOSE: 02/25/2015 07:32:29: Build PVS farm values

    This script directly outputs to Microsoft Word, please install Microsoft Word

    PS C:\scripts>

    Reply

Leave a Reply