Scripted Actions - Windows Scripts
Windows Scripts are scripted actions that are run directly on the Virtual Machine. They can be thought of as "sign in scripts," except they are executed machine-wide and performed as part of the provisioning process for creating or removing session hosts, or running commands against the desktop image VMs for installing/updating software and other tasks.
How it Works
Nerdio Manager uses the custom script extension to execute PowerShell code on the Virtual Machine. Please refer to this Microsoft article for details about custom script extensions for Windows.
Note: Nerdio Manager also uses the custom script extensions for other tasks, such as installing FSLogix and AVD agents.
The code is taken from the Nerdio Manager scripted actions library and is passed to the extension to be run on the VM. Certain variables are passed with it, such as $DesktopUser, which are defined depending on which VM Nerdio Manager is passing the script to.
There are several considerations to keep in mind and most of them are applicable to custom script extension as a whole. Please refer to this section of the Microsoft article for details about tips and tricks related to custom script extensions.
Custom Script Extensions have a 90-minute timeout. This means that if a script is stuck or taking too long to complete, it fails after 90 minutes. This is a limitation set by Azure. This also means that if a script is stuck prompting for user input, it takes 90 minutes to fail.
The script is run with administrative privileges and does not interrupt other sessions. This means that most scripts are safe to run while users are on the VM.
Scripts that cause reboots fail the entire process. The extension is waiting for the PowerShell script to complete fully, and if a reboot is started, it fails. For actions that require restarts and then additional actions, split the script up into multiple scripts, and use "individual with restart" functionality, then place the rest of the scripts in order.
Troubleshooting the Extension
The major component of Windows Scripts is "custom script extension" (aka"CSE" or "CSExtension"). Thus, most of the troubleshooting is essentially performed using processes specific to it. Please refer to this section of the Microsoft article for details about troubleshooting custom script extensions.
As mentioned in the Microsoft article, C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension is the primary location to examine when troubleshooting, because it contains the direct output of the code execution.
Testing the Code
We recommend that you use an isolated "development" session host and running the scripts directly on the host to test your scripts. This ensures that the PowerShell code itself is functional and performs as desired, and provides quick results, as opposed to running the commands through Nerdio.
Comments (0 comments)