LoginVSI PowerShell – Automate Tests

I have a PowerShell function that preps my lab and another executes a single LoginVSI test.  Now, I need to fully automate my LoginVSI testing to perform multiple tests without any interaction.  I need to do the following:

  1. Perform a test for each Master VM I specify
  2. For each Master VM, test specific workloads
  3. For each workload, test specific Virtual Apps and Desktops policies
  4. Perform each test twice, for 60 minutes each

If I have 1 master VM, 2 workloads, and 3 different policies, and I want each test to run twice, this script will run a total of 12 times

  • VM-1, Workload-1, Policy-1,Test-1
  • VM-1, Workload-1, Policy-1,Test-2
  • VM-1, Workload-1, Policy-2,Test-1
  • VM-1, Workload-1, Policy-2,Test-2
  • VM-1, Workload-1, Policy-3,Test-1
  • VM-1, Workload-1, Policy-3,Test-2
  • VM-1, Workload-2, Policy-1,Test-1
  • VM-1, Workload-2, Policy-1,Test-2
  • VM-1, Workload-2, Policy-2,Test-1
  • VM-1, Workload-2, Policy-2,Test-2
  • VM-1, Workload-2, Policy-3,Test-1
  • VM-1, Workload-2, Policy-3,Test-2

As you can imagine, automating this entire process is a huge time saver.

$Testdesc = "ExperimentalVDA" #Name of test scenario
$Workloads = @("TaskWorker","KnowledgeWorker") #LoginVSI workloads to execute
$MasterVMs = @("Win10-718","Win16-718") #Master VM images used for tests
$VMs = @("W10-VSI-04","W16-VSI-04") #VDI VMs used for single server test
$MachineCatalogName = @("VSITarget-Win10","VSITarget-Win16") #Machine catalog name for each test
$PublishedApp = @("VSIDesktop10","VSIDesktop16") #Published desktop/app used for the test
$Policies = @("WAN", "UserExperience") #Policy used for each workload
$DomainName = "SNPP" #Domain
$VSIShare = "\\VSI-Mgmt\vsishare" #LoginVSI share path
$VSIProfileName = "StandardProfile" #LoginVSI profile to use
$Launchers = "VSI-Launcher" #LoginVSI launcher machine
$XSMaster = "XS2.snpp.local" #XenServer master server
$cycles = 2 #Number of times to run each LoginVSI test
$Duration = 60 #Duration for each LoginVSI test
$xdcontrollers = "DDC-test.snpp.local" #XenDesktop controller
$storageResource = "XS_SharedStorage" #Storage resource name defined in Citrix Studio
$hostResource = "XenServer" #Hypervisor host connection defined in Citrix Studio
$XenServerPowerShell = "\\dc1\Automation\Software\PowerShellModules\XenServerPowerShell\XenServerPSModule"
$XenServerUsername = "name" #XenServer username
$XenServerPW = "password" #Password for XenServer
$VSILogFile = "\\dc1\automation\LoginVSI\TestResults\VSITestSummary.txt" #Path to the summary log file

The next step is to load the PowerShell modules. the LoginVSITesting.psm1 is a custom module that contains a few functions to help automate LoginVSI testing.

add-pssnapin Citrix*
Import-module "\\dc1\Automation\Software\PowerShellModules\LoginVSITesting\LoginVSITesting.psm1" -force
Import-module "C:\Program Files\Citrix\Telemetry Service\TelemetryModule\Citrix.GroupPolicy.Commands.psm1" -Force

The first loop sets up my master VM image. I’m calling the following functions from my custom LoginVSITesting.psm1 file

Once the master VM gets updated, we update the published resource that LoginVSI will use by modifying the VSILauncher.ini file from the LoginVSI Profile.

$i = 0
Foreach ($MasterVM in $MasterVMs) {

    # Update MCS Catalog with master VM image
    update-MCSCatalog -XDControllers $xdControllers -MachineCatalogName $MachineCatalogName[$i] -MasterImage $MasterVM -StorageResource $StorageResource -HostResource $HostResource -XSMaster $XSMaster -XenServerUsername $XenServerUsername -XenServerPW $XenServerPW

    #Update LoginVSI Published App to launch
    $resource = $PublishedApp[$i]
    $VSIConfig=Get-Content $VSIShare\_VSI_Profiles\$VSIProfileName\_VSI_Configuration\_CurrentTest\VSILauncher.ini
    $VSIConfig  | Foreach-Object {
        $_ -replace "CCL=.+", "CCL={VSISHARE}\_VSI_Binaries\Connectors\SFConnect.exe /url http://$XDControllers/Citrix/Store /user {domain}\{username} /password {password} /resource $Resource #"
    } | Set-Content $VSIShare\_VSI_Profiles\$VSIProfileName\_VSI_Configuration\_CurrentTest\VSILauncher.ini

The second loop deals with setting the correct LoginVSI Workload. I simply modify the global.ini file with the correct workload name.

    # Loop for each workload
    Foreach ($Workload in $Workloads) {

        # Update Workload
        $VSIConfig=Get-Content $VSIShare\_VSI_Profiles\$VSIProfileName\_VSI_Configuration\_CurrentTest\global.ini
        $VSIConfig  | Foreach-Object {
            $_ -replace "Workload=.+", "Workload=$Workload"
        } | Set-Content $VSIShare\_VSI_Profiles\$VSIProfileName\_VSI_Configuration\_CurrentTest\global.ini

The third loop configures the correct Virtual Apps and Desktops policies. The first part disables all policies, while the second enables the ones identified within the parameters.

It is important to note that if you do this in a production environment, it will DISABLE all policies.

        # Loop for each policy
        Foreach ($Policy in $Policies) {
            # Disable all policies
            new-psdrive -name LocalFarmGPO -PSProvider CitrixGroupPolicy -Controller $XDControllers \
            $CTXPolicies = Get-CtxGroupPolicy
            Set-CtxGroupPolicy -PolicyName $CTXPolicies.policyName -type User -Enabled $false
            Set-CtxGroupPolicy -PolicyName $CTXPolicies.policyName -type computer -Enabled $false

            # Enable policy for test
            Set-CtxGroupPolicy -PolicyName $Policy -type Computer -Enabled $true
            Set-CtxGroupPolicy -PolicyName $Policy -type User -Enabled $true
            Remove-PSDrive -name LocalFarmGPO

With the Master VM, workload and policies set, the script kicks off the LoginVSI test by calling the following function from the custom LoginVSITesting.psm1 file

            # Start Login VSI Test
            Start-NewCitrixVSITest -Testdesc $testdesc -Workload $Workload -VMs $VMs[$i] -DomainName $DomainName -VSIShare $VSIShare -VSIProfileName $VSIProfileName -Launchers $Launchers -XSMaster $XSMaster -cycles $cycles -Duration $Duration -MasterImage $MasterVM -XenServerUsername $XenServerUsername -XenServerPW $XenServerPW -VSILogFile $VSILogFile -VMMetrics
    $i = $i + 1

I can now walk away and come back later to review the results.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.