Skip to content

Powershell

Citrix PVS and PowerShell

Hi all

Today’s post is about Citrix PVS (PVS) and Powershell. This combination has been a pretty awful experience for a long time, but now things a looking up. Since PVS version 7.1x where Citrix released a Powershell module instead of MCLI commands we have been able to use some real powershell commands and logic. In this article I will show you how to do commen PVS task with powershell.

XenServer documentation script

Hi all,

Just before new years I uploaded my XenServer documentation script to GitHub, you can find it here:

In this post I will go through how to use the script and how to report any feedback to me. I also want to do a huge shoutout to Iain Brighton for making the PScribo module which is just awesome for report making!

  1. Download the code from here: https://github.com/mracket/XenServer-DocumentationScript/archive/master.zip
  2. Download PScribo from here: https://github.com/iainbrighton/PScribo/archive/dev.zip
  3. Download PowerShell SDK for XenServer here: https://www.citrix.com/downloads/xenserver/product-software/xenserver-73-standard-edition.html
  4. Place the PScribo and XenServer SDK module in the PowerShell modules folderPowerShellModulesFolder
  5. Set your PowerShell execution policy for unrestricted while running the script, this can be done with the following command while you are in PowerShell commandline as administrator “Set-ExecutionPolicy Unrestricted”. If you don’t know which execution policy you have running you can see it with this command “Get-ExecutionPolicy” PowerShellExecutionPolicy
  6. While running the PowerShell commandline change to the folder where you placed the downloaded script and run the script like this “.\New-XenServerReport.ps1 -PoolMasterIP 10.10.10.10 -UserName root -Password Password -ReportFormat html -Verbose”. Remember to change the values to fit your environment. The parameters supports tab-complete. Also remember that you can add more pools at the same time by just adding poolmasters like this -PoolMaster “10.10.10.10”,”10.10.10.20″,”10.10.10.30″
  7. The script will output the poolmaster that it is working on and return to the prompt when done. ScriptComplete.png
  8. The report will be placed on your desktop (I will add a paramter to this later on) and you can then open it with your favorite browser, word or text editor depending on which output format you selected.
  9. A report will look like this: XenServerReport.png
  10. Remember to set back your PowerShell execution policy to what you had before running the script

I hope you can use this script for your environments and if you have any enhancements you want in the script let me know. You are also more than welcome to provide any other feedback and bugs to me via twitter @mracket or the GitHub page https://github.com/mracket/XenServer-DocumentationScript/issues

/Martin

Pester for XenApp 6.5

Hi,

I am currently working on a project where we are building a new XenApp 6.5 environment (Yes, we know it’s not the best idea, but there are reasons). For this project with need to hand in an operational acceptance test (OAT) and part of that is showing that the infrastructure is working as expected. After watching a youtube video from PSConf.eu (https://www.youtube.com/watch?v=Qy-uvT57pt8 I was inspired to use Pester as the base for doing the infrastructure server tests. Of course, there is more to the OAT but I won’t look into that is this post.

For those of you that has never heard about Pester it is basically a “tool” that will test your PowerShell code and alert you of anything in the code that doesn’t behave as you intend. If you really want to dig into PowerShell coding you should start with writing your Pester tests and then your PowerShell code afterwards. This force you to think about what you want to achieve and create the tests for it before you write the code doing it. You can read more about Pester here: https://github.com/pester/Pester/wiki/Pester

After watching the video from Rob I started right away on building my Pester tests so much of my evenings this week has gone with this. Writing a Pester test isn’t that hard and doesn’t take much time, but finding out what to test and how to test it can take a bit of time.

So, what did I do to get started with Pester?

As stated I watched the video on youtube and then I found this post by Adam Bertram: https://mcpmag.com/articles/2016/12/01/create-a-simple-pester-test-report.aspx

After that I made a list over the infrastructure roles I wanted to test, my list looks like this:

Citrix XenApp 6.5 Zone Data Collector

Citrix XenApp 6.5 Worker

Citrix StoreFront

Citrix PVS

Microsoft App-V

My next step was to examine the services running on the infrastructure servers and note down the display name and name of each service.

For each of these services I created a Pester test looking like this:

it "Citrix PVS Soap Server" -Skip:$ServerAlive{
                (Get-Service -Name soapserver -ComputerName $PVSServer).Status | Should be "Running"
}

Since I wanted to be able to separate the roles I created loops for each role and feeding all servers from a specific OU into these loops. The base is looking like this:

Foreach ($PVSServer in $PVSServers) {
    If (Test-Connection -ComputerName $PVSServer -ErrorAction 0 -Count 1 -Quiet) {
        $ServerAlive = $false
    } Else {
        $ServerAlive = $true
    }
    Describe "Check Citrix Infrastructure on $PVSServer" {
        Context "Citrix PVS" {
            it "Citrix PVS Soap Server" -Skip:$ServerAlive{
                (Get-Service -Name soapserver -ComputerName $PVSServer).Status | Should be "Running"
            }
            it "Citrix PVS Stream Service"  -Skip:$ServerAlive {
                (Get-Service -Name StreamService -ComputerName $PVSServer).Status | Should be "Running"
            }
            it "Citrix PVS Two-Stage Boot Service"  -Skip:$ServerAlive {
                (Get-Service -Name PVSTSB -ComputerName $PVSServer).Status | Should be "Running"
            }    
        }
    }
}

I quickly found out that I can just settle for services, I need to have at least open ports and registry settings in the Pester tests as well. You can see the examples below:

it "Port 1494 is open" -Skip:$ServerAlive {
                    (Test-NetConnection -ComputerName $XA65Server -Port 1494).TcpTestSucceeded | should be "True"
}
it "Initial database name" -Skip:$ServerAlive {
                    $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$XA65Server)
                    $KeyPath = 'software\policies\Citrix\ima\database settings'
                    $CitrixDatabaseName = $Reg.OpenSubKey($KeyPath)
                    $CitrixDatabaseName = $CitrixDatabaseName.GetValue('InitialDatabaseName')
                    $CitrixDatabaseName  | Should be $InitialDatabaseName
}

All this combined has made up what I am needing right now, but I am sure that I will find more tests I want to implement in this XenApp 6.5 environment so this post might be updated later as well.

The last part of the Pester setup for me was to create a nice report that I can show to the project manager so that he knows that has been tested and what the status is. For instance, I know there are errors in the environment, but they should not be fixed right now. Putting it into a report was easy, but I had some trouble getting the EXE file needed. The EXE file is for ReportUnit (http://reportunit.relevantcodes.com) but their download didn’t work for me so I was in luck that the community is there because Rob Sewell @sqldbawithbeard send the EXE to me and in 5 mins the report was ready.

The report looks like this and it is awesome if I should say so!Screenshot_4

If we look a bit deeper in the HTML report you can see both skipped and failed tests. The skipped tests are because I first test if the server is online, if it isn’t I skip the tests that were meant to run on it. The failed attempts speak for themselves and you can see below one of the tests that are failed. Screenshot_2.png

Screenshot_1.png

This was a short intro into how I got started with Pester. In the future I am sure I will create the same tests for XenApp 7.x and the surrounding components. If you are interested in these let me know.

/Martin