Using VMM to run scripts to manage remote Hyper-V hosts

When it comes to the bulk management of Hyper-V hosts (or of any Windows server, for that matter), I have always gravitated toward the use of PowerShell. Even so, using PowerShell to manage a collection of hosts tends to involve more coding than whatever happens to be required for the management activity you are trying to perform. Typically, for instance, you will need a list of the servers to be managed, and you will need some sort of looping structure that performs the management task against each server on the list. Although this method of using PowerShell to manage remote hosts works really well, there is a way to simplify things a bit. If you have System Center Virtual Machine Manager (VMM), you can use its management console as a tool for running a script against one or more hosts, without the hassle of writing code to loop through the list of hosts. Incidentally, you aren’t limited to working solely with PowerShell. You can also launch scripts from the Windows command prompt. Let’s take a look at how it’s done.

To get started, open the VMM Management Console, and then select the VMs and Services workspace. Next, expand a host group, and click on the host that you want to manage. When you do, you will see a Host tab appear on the toolbar at the top of the screen. As you can see in the image below, this toolbar contains an option to run a script command.


Upon clicking on Run Script Command, you will be taken to the Run Script Command dialog box, which you can see in the image below.


As you can see, the Run Script Command dialog box includes several fields. One of the first fields that you need to be familiar with is the Executable Program field. While it may be tempting to populate this field with the name of your script, this field is actually used to launch the scripting environment.

Based on the documentation that I have found, it seems that Microsoft has intended for this field to be used exclusively with the Windows Command Prompt environment (CMD.EXE). It is possible to run PowerShell scripts, but you have to jump through a couple of hoops to make it happen. As such, I need to first familiarize you with running Command prompt commands, and then I will show you how to adapt the procedure to support PowerShell.

Running Windows command prompt commands

As I have spent time working with the Run Script Command dialog box, I have found that it is extremely picky when it comes to the command syntax that you use. That’s why I want to begin by showing you how to execute a command prompt command.

It seems that four elements absolutely must be present to make a command prompt command execute properly. The first of these elements is that as previously noted, the Executable program must be set to cmd.exe. The .EXE portion of the command is important because the command will fail without it.

The second element that you must have in place is a /Q in the Parameters field. The /Q parameter tells Windows to run the Command Prompt environment in “echo off” mode. In case you are wondering, echo off was an old DOS command that hid certain output from view.

The third required element is the /C switch, which must also be expressed in the Parameters field. This switch tells the Command Prompt window to run the command and then terminate. If you omit this switch, then the job associated with the script will hang.

The fourth required element is the actual command that you want to run within the Windows command prompt environment. The example that Microsoft gives in its documentation is:

Net start sftlist

In case you are wondering, this command starts the sftlist service. You can see what the fully populated Run Script Command dialog box looks like in the screenshot below:

Running PowerShell scripts

Although the Microsoft documentation does not say anything about running PowerShell scripts through the Run Script Command dialog box, I have found a way to do it. Again, the dialog box is picky about the syntax that you use.

Like before, you will need to enter cmd.exe as the executable program name, and you will have to include /q and /c at the beginning of the Parameters field.

The next step is to type powershell.exe in the list of parameters. Again, you must include the .exe portion of the command, or PowerShell will fail to launch.

Finally, you will need to append the -File parameter, followed by the path and filename of the script that you want to test.

When I was testing this procedure out, I created a script called copy.ps1 that simply copied a file from one folder to another (so that I could verify that the script was indeed executing). The image below shows the commands that I used to launch the script.

How do I know if the VMM script worked?

When you use VMM to execute a script, you won’t see the scripting environment visibly open on the remote host server. The best way to find out if VMM successfully launched the script or not is to take a look at the Jobs workspace. The image below shows some examples of some successful jobs and some failed jobs. You will also notice that there are a few canceled jobs. I had to cancel these particular jobs because omitting the /Q and /C switches caused the jobs to hang. In any case, it can sometimes be tricky to come up with just the right syntax for running a script, and the Jobs menu can help you to refine your technique and to confirm whether or not your VMM script ran.

Featured image: Designed by Freepik

Brien Posey

Brien Posey is a freelance technology author and speaker with over two decades of IT experience. Prior to going freelance, Brien was a CIO for a national chain of hospitals and healthcare facilities. He has also served as a network engineer for the United States Department of Defense at Fort Knox. In addition, Brien has worked as a network administrator for some of the largest insurance companies in America. To date, Brien has received Microsoft’s MVP award numerous times in categories including Windows Server, IIS, Exchange Server, and File Systems / Storage. You can visit Brien’s Website at: www.brienposey.com.

Share
Published by
Brien Posey

Recent Posts

Review: Identity verification solution Specops Secure Service Desk

Specops Secure Service Desk is an innovative solution for positively identifying a user who calls…

4 hours ago

Apple Silicon: What it means for the world of personal computing

Apple is moving away from Intel processors to use its own Apple Silicon processors to…

7 hours ago

RAID 0 vs. RAID 1: When to use each level and why

Two of the most popular RAID levels for improving performance are RAID 0 and RAID…

10 hours ago

Got cybersecurity tools? Good. Got too many? That may be a problem

Strength in numbers may not apply to cybersecurity tools. In fact, using too many tools…

1 day ago

Getting started with System Center Operations Manager

System Center Operations Manager can monitor your IT resources, but the tool is only as…

1 day ago

Microsoft 365 administration: Creating DNS records for email security

Microsoft 365 administration has many facets, but none is more important than configuring email. Here’s…

1 day ago