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

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.RunScript[T](String scriptName, String scriptBody, Dictionary`2 parameters, Object[] constructorArgs, IScriptDebug iScriptDebug, Boolean bSerializeOutput)


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:


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:


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:



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…


  1. every time I put in a newline and close the editor it removes it. I reopen and it looks like ]]>

    1. Did you put the script in the MP fragment or a separate file? I put it in a separate file and use $IncludeFileContent to embed the script into the fragment.

  2. Hi.

    thanks, thanks, thanks !

    Yes, it works with the empty line at the end of the file. I also use $IncludeFileContent.

    I think it took me more than two hours this morning:
    Using the Microsoft.Windows.PowerShellWriteAction Module in an Agent Task.
    When executing the Task it simply said “No output”. Nothing more. No DEBUG-Messages, no error log entries, nothing.
    I started reading the docs. Found for Module Microsoft.Windows.PowerShellWriteAction. Then I got this strange Errormessage “System.Management.Automation.IncompleteParseException ….” .
    Running the script on the commandline, no error, works fine.
    Nevertheless I started to make a “manual” code review, testing again…

    At the end I asked BIng ( yes, really) and found this blog entry.
    So again, thanks to Tao !


    1. Well in my previosu post I entered an HTML/XML tag, which was removed on processing the reply…
      I wanted to report this:
      I found the XML-Tag “StrictErrorhandling” for the PowerShellWriteAction Module.
      Settign this true enabled the error-messages. If omitted it defaults to false and when running into the error we are discussing here, you simply see “No Output”.

  3. This is a silly problem. SCOM can be very fickle with scripts. I had a similar problem, but my problem was that I had a Remove-Variable function as the last line in the script (for testing). Once I removed that line, everything worked.

Leave a Reply

%d bloggers like this: