System.Management.Automation.IncompleteParseException for a PowerShell script from my Management Pack

less than 1 minute read

I’m currently working on a management pack that I’m hoping to be released to public very soon. In one of the workflows in the MP, I got an error logged in the Operations Manager event log on the target agent:

The PowerShell script failed with below exception

System.Management.Automation.IncompleteParseException: Missing closing ‘}’ in statement block. at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at Microsoft.EnterpriseManagement.Common.PowerShell.RunspaceController.RunScriptT

image

Needless to say, the script runs just fine manually on the agent, so it is bug free. Took me a while to day to figure out what the issue is.

The script ended like this:

SNAGHTML308e8f82

The last line is commented out, I’d uncomment it when test run it in powerShell prompt on an agent. When the MP is built in VSAE, it looked like this:

SNAGHTML308f9e91

It’s on the same line as the CDATA close tag. After I started a new line at the end of the script, the MP started working:

SNAGHTML30912afd

SNAGHTML30923e81

From now on, I’ll remember to end the PowerShell script with an empty line. Interestingly, another VBScript in the MP doesn’t have this issue…

Leave a comment