• Blog
  • Webinars
  • Partner
  • Support
  • Contact
  • EN
    • DE
ScriptRunner
  • About us
    • Team
    • Jobs
    • Press
  • Why
  • Use Cases
  • Software
    • ScriptRunner Server
    • ScriptRunner Portal
    • ScriptRunner Portal Widget
    • ScriptRunner Connectors
    • ScriptRunner ActionPacks
  • Try Now
  • Search
  • Menu Menu
You are here: Home1 / ScriptRunner Blog2 / News3 / Using PowerShell to Create New Citrix MCS Machines

Using PowerShell to Create New Citrix MCS Machines

Author: Guy Leech | Reading time: 8 minutes | Category: News, PowerShell & Systems

Citrix Virtual Apps and Desktops (CVAD) includes two mechanisms which allow new machines to be quickly created in order to add additional capacity for end users. These are Machine Creation Services (MCS) and Provisioning Services (PVS).

This article does not go into details of how these work or how to set them up and assumes that a machine catalogue using MCS has already been created – we shall show how to use PowerShell to create brand-new machines in this catalogue and assign them to a delivery group.

It is of course possible to create the MCS based machine catalogues themselves with PowerShell – in fact, a whole CVAD implementation can be built from scratch with PowerShell if required.

Table of content

  • Prerequisites
  • Creating Active Directory Machine Accounts
  • Creating Virtual Machines
  • Adding the Machines to a Catalogue
  • Adding the Machines to a Delivery Group
  • Powering on the Machines
  • Conclusion
  • ActionPack for Citrix
  • Related links

Prerequisites

Prior to performing the steps to create the machines, the CVAD PowerShell cmdlets must be loaded. Prior to release 1912 (LTSR), these were provided as (legacy) snap ins whereas from that release onwards they are available as modules (read the first part of this series for more information: An Introduction to PowerShell in Citrix Virtual Apps and Desktops).

The following code will work on all releases to load the cmdlets used in this post:

The code can be run on a Citrix Delivery Controller or on any machine where Citrix Studio or the CVAD PowerShell cmdlets are installed where the latter is preferred for resource consumption reasons. If the latter is used, the parameter -AdminAddress must be specified to the Citrix cmdlets in order to direct the calls to a specified delivery controller.

Creating Active Directory Machine Accounts

Since we are assuming that we are adding machines to an existing catalogue, various internal structures which the PowerShell code needs will already have been created although these are not visible as discrete entities in Citrix Studio.

One of these will be an identity pool which, if created by Citrix Studio, will have the same name as the catalogue to which it applies and contains the naming convention chosen when the catalogue was created (see figure 1).

Screenshot: Citrix Studio, Machine Catalog Setup

Fig. 1: When setting up a machine catalogue you must also define a naming convention for its machines

We can check that the identity pool we require exists with the following command:

Figure 2 shows the output.

Screenshot: Checking whether a certain identity pool exists via PowerShell

Fig. 2: Using Get-AcctIdentityPool to check whether a certain identity pool exists

Which we can see correspond to the MCS machine catalogues in existence (figure 3):

Screenshot: List of catalogs containing MCS machine catalogues

Fig. 3: The list of catalogues shows the existing MCS catalogues

To create the Active Directory accounts for the new machines, we run the following which creates two machine accounts using the naming convention and OU defined in the specified identity pool – note that we do not have to specify the name, or name base, ourselves:

We have assigned the result to a variable as we will be using it in the next step, but we can check the result by looking at the contents of this variable (figure 4):

Screenhot: PowerShell output of variable $newAccounts

Fig. 4: Content of the variable $newAccounts

If you check AD, you should see these machine accounts have been created in the correct OU.

Creating Virtual Machines

We now need to create the virtual machines corresponding to these AD accounts and for this we need the provisioning scheme name which will have been created when the MCS machine catalogue was created and, as with the identity pools, will have the same name as the catalogue to which it pertains.

Screenshot: Retrieving the provisioning scheme name via PowerShell

Fig. 5: Retrieving the provisioning scheme name via PowerShell

When creating the VMs, we create a task which can either be run synchronously, so the cmdlet will not return until the task has fully completed, or run asynchronously such that the cmdlet returns immediately. In the latter case you have to check that the task has completed before continuing although this can be useful if the task could take a long time to run such that other actions need to be performed or a progress indicator needs to be displayed.

Here we run it async in order to show how we check that the task has completed.

The task GUID is stored in the variable which we can query, as seen in figure 6:

Screenshot: Properties of $taskDetails

Fig. 6: Properties of $taskDetails

Notice the Active, Status, TaskState and TaskStateInformation properties which we can use to test whether the task has completed or not. Note that when checking the properties in a loop, have some kind of delay, such as via Start-Sleep, to reduce the CPU consumption of this polling loop.

Adding the Machines to a Catalogue

Now that we have created the VMs, which can be verified in your hypervisor console, we can add them as machines to a machine catalogue. The sample below has a placeholder for error handling if an error should occur – do not neglect error checking/reporting!

Figure 7 shows that the execution was successful:

Screenshot: search results in Citrix Studio for

Fig. 7: The search result shows all VMs that are part of the “MCS Server 2019” machine catalogue

Adding the Machines to a Delivery Group

In order for these newly created machines to be available for end users, they need to belong
to a delivery group which is achieved by running the following:

As expected, figure 8 shows that the machines have been successfully added to the Delivery Group.

Screenshot: search results in Citrix Studio for

Fig. 8: The search result shows all VMs that are part of the “MCS Server 2019” Delivery Group

Powering on the Machines

Assuming this succeeds, all that remains to be done is to power on these new machines so that they boot, register with a delivery controller and thence become available to provide published applications and/or desktops.

Notice in the PowerShell below that it changes the computer account name contained in the $taskDetails variable by removing the “$” character at the end of the name to turn it into an AD computer name.

This is achieved with a regular expression (regex) where $ is a special character meaning the end of the string, so we have to escape it using the backslash character.

If everything has worked correctly, Citrix Studio should now show the newly created machines (figure 9) and after a short delay, to allow them to boot, they should be registered and thus capable of being used to supply apps and/or desktops that use the delivery group.

Screenshot: Overview of the newly created VM in Citrix Studio

Fig. 9: Overview of the newly created VM in Citrix Studio

Conclusion

Configuring new VM with MCS via PowerShell offers the typical advantages of scripted solutions: Accuracy, standardizability and reproducibility. The resulting time savings are also not to be ignored.

However, in combination with ScriptRunner, even more opportunities open up: For example, the creation of new VMs can be fully automated and even delegated to helpdesk and end users. All processes remain secure, error-free and traceable.

We would be happy to discuss with you how you can implement these or other use cases in your company with ScriptRunner. Simply book an appointment with our product experts.

ScriptRunner ActionPack for Citrix

Free PowerShell Script Collection

ActionPack for Citrix

Getting started with PowerShell task automation is now even faster and easier with our new ScriptRunner ActionPack for Citrix!

200 ready-to-use PowerShell scripts are now freely available on the ScriptRunner GitHub repository.

Download for free from GitHub >

Related links

  • Create machine catalogs | Citrix product documentation
  • An Introduction to PowerShell in Citrix Virtual Apps and Desktops | ScriptRunner Blog
Share this article
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
  • Share on Reddit
  • Share by Mail

These articles might also be interesting for you:

ScriptRunner ActionPack for CitrixScriptRunner Software GmbH

ScriptRunner ActionPack for Citrix

11. March 2021
Read more
https://www.scriptrunner.com/wp-content/uploads/2021/03/citrixactionpack.jpg 441 441 Heiko Brenn, Head of International Business https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Heiko Brenn, Head of International Business2021-03-11 13:02:162021-03-11 14:46:04ScriptRunner ActionPack for Citrix
Article: Using PowerShell to Create New Citrix PVS MachinesScriptRunner Software GmbH

Using PowerShell to Create new Citrix PVS Machines

4. March 2021
Read more
https://www.scriptrunner.com/wp-content/uploads/2021/02/powershell-create-citrix-machines.png 1000 1000 Guy Leech https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Guy Leech2021-03-04 09:00:552021-03-12 17:07:43Using PowerShell to Create new Citrix PVS Machines
Article: An Introduction to PowerShell in Citrix Virtual Apps and DesktopsScriptRunner Software GmbH

An Introduction to PowerShell in Citrix Virtual Apps and Desktops

7. December 2020
Read more
https://www.scriptrunner.com/wp-content/uploads/2020/12/citrix-virtual-desktops_Zeichenfläche-1.png 1000 1000 Guy Leech https://www.scriptrunner.com/wp-content/uploads/2018/05/ScriptRunner_Logo_RGB-300x45.png Guy Leech2020-12-07 17:01:102021-03-12 16:59:28An Introduction to PowerShell in Citrix Virtual Apps and Desktops

About the author:

Guy Leech

Consultant, Software Developer, Troubleshooter.
Current Citrix CTP, VMware vExpert, and Microsoft MVP. Inventor of AppSense Application Manager. PowerShell addict.

Latest posts:

  • Article: PowerShell PSDefaultParameterValuesScriptRunner Software GmbHPowerShell PSDefaultParameterValues24. March 2021 - 14:10
  • Article: ScriptRunner is sponsoring the PowerShell + DevOps Global Summit 2021ScriptRunner Software GmbHScriptRunner is sponsoring the PowerShell + DevOps Global Summit 202119. March 2021 - 10:00
  • ScriptRunner ActionPack for CitrixScriptRunner Software GmbHScriptRunner ActionPack for Citrix11. March 2021 - 13:02
  • Artikelbild:ScriptRunner Software GmbH5 PowerShell Scripting Best Practices – From Runnable to Professional Code10. March 2021 - 10:00
  • Artikelbild: Vorschau auf das Produktjahr 2021ScriptRunner Software GmbHPreview of the product year 20219. March 2021 - 10:00

Product

  • ScriptRunner Platform
  • ScriptRunner Server
  • ScriptRunner Portal
  • ScriptRunner Portal Widget
  • ScriptRunner Apps
  • ScriptRunner Connectors
  • Script Collections
  • Licensing
Get your free trial

Solutions

  • IT Administrators
  • IT Team Leaders
  • Use Cases

Resources

  • Blog
  • Documentation
  • Knowledge Base
  • Webinars
  • PowerShell Lexicon
  • PowerShell Poster
  • PowerShell Security Ebook

Company

  • About us
  • Team
  • Jobs
  • Press
  • References
  • Partner

Contact

ScriptRunner Software GmbH
Ludwig-Erhard-Straße 2
76275 Ettlingen
Germany

T: +49 7243 20715-0
M: info(at)scriptrunner.com

Request Demo
© ScriptRunner Software GmbH is a subsidiary of AppSphere AG
  • LinkedIn
  • Xing
  • Twitter
  • Facebook
  • Youtube
  • Imprint
  • Privacy Policy
  • Newsletter
An Introduction to PowerShell in Citrix Virtual Apps and Desktops Article: An Introduction to PowerShell in Citrix Virtual Apps and DesktopsScriptRunner Software GmbH Article: X-mas Fun with PowerShell and ScriptRunnerScriptRunner Software GmbH X-mas Fun with PowerShell and ScriptRunner
Scroll to top