PowerShell in Citrix
By CMD Technology Group
4 min read
Everything a Citrix administrator does in Citrix Studio and many other Windows based components is translated to PowerShell commands. So, what is PowerShell? In general, Windows PowerShell is a scripting language designed for task automation and configuration. The ‘shell’ part of the name comes from the interface. In computers, a shell is an interface that allows you to access functions and services within an operating system. Windows PowerShell is a command-line interface that provides administrators with an interactive scripting environment. PowerShell provides instruction sets known as ‘cmdlets’ that perform functions. Cmdlets can be written and added to PowerShell which is what Citrix has done for XenApp, XenDesktop, and other products.
The PowerShell plug-in which loads the Citrix related cmdlets is installed on Delivery Controllers automatically and other servers with installed Citrix products that utilize PowerShell. If you are doing quick maintenance commands on your Citrix environment, then working on one of the delivery controllers may be just fine for you. However, if you want to do some custom scripting, then working on the delivery controllers may not be an ideal location. It is always nicer to be able to do work on your own system. Also, it is preferable to access a production server only when required. To that end, you can install the Citrix PowerShell plug-ins on other systems by doing the following:
Access the installation media through file explorer and go to the ‘\x64\Citrix Desktop Delivery Controller’ directory
Search for all files with the word ‘PowerShell’ in it
Copy them to another directory (i.e., C:\temp\CTXPS)
Open PowerShell as an administrator
Change directory to the directory that has the PowerShell files in it
You need to use msiexec.exe to install each .msi file in this directory. This can be one at a time (time-consuming), or you can run them all at once. To run them all at once, read through the following steps before you attempt it.
The following lines are for installation of XenApp and XenDesktop 7.15 LTSR CU3. If you are installing the same version, copy all the following lines and paste them directly into the PowerShell window and press enter. If you are installing a different version, copy the files to notepad and modify as needed (i.e., add or remove lines as needed or change names). Once modified, copy the lines into the PowerShell window and press enter.
The .msi files will be installed, but pay attention to the next lines of instruction and do not cancel anything
PowerShell can only run one installation at a time. The first file run will come back as finished. The rest will give this error
Click finish on the first one
And then, click retry on one of the ones that came back with the error. It will now finish. Go back and forth finishing and then retrying the next on till they are all done.
Now that all the plugins have been installed on the system, we can move on to using them. When you first open PowerShell, you cannot use the Citrix commands until they are loaded. To load the Citrix PowerShell Plugins, use the command ‘ASNP Citrix*’:
ASNP is a short form of the PowerShell command ‘Add-PSSnappin.’ The parameter ‘Citrix*’ refers to all the Citrix related plugins. You will now have access to the Citrix defined cmdlets along with the existing PowerShell cmdlets. At any time, if you need help with a cmdlet, you can use ‘Get-Helpcmdlet
Now that you know what PowerShell is and how to load the Citrix defined cmdlets, you may be wondering how you would use PowerShell in a Citrix environment. You may access PowerShell and use individual cmdlets for gathering information, quick configuration changes, and/or troubleshooting. For instance, a very commonly used cmdlet is ‘Get-BrokerController’. This is used to get information about the Delivery Controllers in a site. If you need to find information about the database the environment is connected to, use the cmdlet ‘Get-BrokerDbconnection’. You may have noticed when you open a Citrix support case; the support engineer may open PowerShell and use cmdlets like these to do their troubleshooting.
The true power of using PowerShell is in scripting. Scripting allows you to automate processes. For instance, one client of ours has multiple PVS sites utilizing the same master images. To ensure that a change to an image in site one is populated to other sites, we used a custom PowerShell script we created. When a new site was added, the script was modified as well. Another use we have had for a PowerShell script involved rebooting servers. Before tagging, rebooting servers more than once a week was not an easy task. We wrote a PowerShell script that rebooted servers only some of the servers in a delivery group each night. For instance, servers 1 through 10 rebooted on Monday and Thursday. Servers 11 through 20 rebooted on Tuesday and Friday. We could have set it to even and odd number servers or other grouping methods. Rebooting of servers could actually be scripted using standard Windows PowerShell cmdlets.
However, with the Citrix cmdlets utilized, the script actually did the following:
That is pretty powerful for an automation script. Even with the new use of tags to help in this type of automation, the reboot script is still being utilized over tags.
Microsoft PowerShell provides tools for you to take more control over your Windows environment. Citrix has added to these tools to allow you to take more control of your Windows based Citrix environment. You may never need them, but it is nice to have them when you do.
Get in touch
You can email us at firstname.lastname@example.org
Give us a call at 1-800-806-4173
Or contact us using the form below