One of the cool new features in System Center Virtual Machine Manager 2012 (SCVMM 2012) is the ability to execute commands remotely to a host. This feature can be useful in scenarios where you want to start a service or collect information from a remote host. You can also use custom resources you added to the scvmm library to run commands. Custom resources can consist of batch files that can execute specific commands against the server but the use of custom resources is not required.
Let’s go over some examples on how to use this feature. The scenario below is the one where we want to start a service on a SCVMM host. In the SCVMM console select a host, then from the toolbar select the Host tab and select Run Script Command.
This will open the following window:
We want to start a service named sftlist, so we will type cmd.exe for the Executable program. For parameters, we will type /q /c net start sftlist. The /q will turn echo off for the command line and /c will carry out the command and then terminates. If you do not use these switches, the outcome will be a return code 0 from the cmd.exe process and it will not display the actual result of the command in the job. Once ready, you can click ok and monitor the job in the scvmm console for the result
If the command fails on the host, you can go to c:\windows\temp and look for a log in the following format, gce_stderrorxxxxxxxxxx.log. This log will have the result of the command that was executed and will match the error returned by the job.
Let’s go over another example, this time using custom resources.
Using a script within a custom resource can help you execute more commands or customize execution. For this to work, the files need to be in the SCVMM library server and the library has to be refreshed. Once you are ready you can select a host. From the toolbar select the Host tab, and then select Run Script Command.
This will open the following window:
For this example we included a batch file named services.cmd under a custom resource folder named troublehoot.cr. The batch will perform a net stop sftlist /y and then a net start sftlist. In the executable program we will type cmd.exe, and in parameters we will type /q /c services.cmd. The /q will turn echo off for the command line and /c will carry out the command and then terminates. If you do not use these switches, the outcome will be a return code 0 from cmd.exe process and it will not display the actual result of the command in the job. Under script resource package, we will select troubleshoot.cr and we will specify a run as account. Once ready, you can click OK and monitor the job in the scvmm console for the result.
In this scenario, the custom resource folder will be transferred to the agent host and copied under windows\temp. A folder with the following format, scvmm.xxxxxxxx, will be created and will contain all the files. From here, it will execute the batch file and the agent will return the corresponding outcome to scvmm and display it in the job. If the script generates an error, it will create a log under c:\windows\temp in the following format, gce_stderrorxxxxxxxxxx.log.
Alvin Morales | Senior Support Escalation Engineer
App-V Team blog: http://blogs.technet.com/appv/
AVIcode Team blog: http://blogs.technet.com/b/avicode
ConfigMgr Support Team blog: http://blogs.technet.com/configurationmgr/
DPM Team blog: http://blogs.technet.com/dpm/
MED-V Team blog: http://blogs.technet.com/medv/
OOB Support Team blog: http://blogs.technet.com/oob/
Opalis Team blog: http://blogs.technet.com/opalis
Orchestrator Support Team blog: http://blogs.technet.com/b/orchestrator/
OpsMgr Support Team blog: http://blogs.technet.com/operationsmgr/
SCMDM Support Team blog: http://blogs.technet.com/mdm/
SCVMM Team blog: http://blogs.technet.com/scvmm
Server App-V Team blog: http://blogs.technet.com/b/serverappv
Service Manager Team blog: http://blogs.technet.com/b/servicemanager
System Center Essentials Team blog: http://blogs.technet.com/b/systemcenteressentials
WSUS Support Team blog: http://blogs.technet.com/sus/
The Forefront Server Protection blog: http://blogs.technet.com/b/fss/
The Forefront Identity Manager blog : http://blogs.msdn.com/b/ms-identity-support/
The Forefront TMG blog: http://blogs.technet.com/b/isablog/
The Forefront UAG blog: http://blogs.technet.com/b/edgeaccessblog/