Restart-Computer acts differently in child SMA runbooks

You should already be aware that Powershell -ne Powershell Workflows. The language is largely transferable, but there is some tweaking that you will need to do. (See: here)

Today, I have realized that there are similar quirks with child workflows vs parent workflows in SMA (Service Management Automation)

Consider the following PS workflow:

workflow MDTestArea2
{
    Param(
        [Parameter(Mandatory=$true)]
            [string] $Computer
    )
    Restart-Computer -PSComputerName $Computer -force -Wait -TimeOut 300 -for wmi
}

This code obviously restarts the computer supplied in the parameter and waits for WMI to initialize. In an SMA runbook or in a Powershell Workflow run from the ISE everything works as intended.

However, consider the following parent workflow:

workflow MDTestArea
{    
    Param(
        [Parameter(Mandatory=$true)]
        [string] $Computer
    )
    MDTestArea2 -Computer $Computer
}

This code, simply calls the previous workflow and supplies the required computer parameter. In a Powershell Workflow run from the ISE, this works. However when this is run from SMA, the following error is generated:

“Compilation error while building dependent workflows. For details see C:\Users\Usernameofyourservice\AppData\Local\Temp\PSWorkflowCompilation\Workflow_RandomID\Project\Build.Log.”

In the build.log file:
XC1014: Assembly ‘Microsoft.PowerShell.Commands.Management’……can not be resolved.

What is interesting is when I modified the first workflow removing the “-for WMI” in the Restart-Computer line of the first runbook, both runbooks executed flawlessly within SMA. To me this means that some commands do not translate well when they are running as a child runbook. As much as I am tempted to submit this as a bug, I can’t see this impacting very many people….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s