Command Shell Examples
Useful SQL Queries
Powershell Scripts - Illegal Variable Name - Jonathan Almquist on Operations Manager - Site Home - TechNet Blogs

Powershell Scripts - Illegal Variable Name

Powershell Scripts - Illegal Variable Name

  • Comments 2
  • Likes

Just figured out this annoying issue I have seen come up many times while saving Powershell script workflows.

For some reason, I would get management pack validation exceptions when trying to save workflows in the Authoring Console.

Note:  The following information was gathered when the operation was attempted.  The information may appear cryptic but provides context for the error.  The application will continue to run.
 
: Verification failed with [1] errors:
-------------------------------------------------------
Error 1:
: Failed to verify Discovery [MyPowershellScript.PS]
Failed to verify referenced module : ID=ScriptInvalid configuration specified for Module [Script]Incorrect expression : '$DatabaseServer)
 
Unable to resolve this expression. Please check this expression for errors. (Hints:  Check for correct character casing (upper case/lower case), mismatched "$" signs, double quotes("), square brackets "[" or "]" ). Here is a sample expression: $Data/EventNumber$

The only workaround was to rename the variable in my script.

This happened on several different occasions.  Even though context around the exception revealed that the MP validator was apparently expecting a $Data variable notation, it simply wasn’t apparent to me why my script variable would always cause failures.

I finally put 2 and 2 together, and realize that this only happened when the Powershell script contained variables like $DatabaseServer, $DatabaseName or $Dataset, just to name a few examples.

Lesson learned – Do not name Powershell variables $Data*.

I do not moderate this blog anymore. If you have a question regarding this post, send me a message.

Comments
  • Yeah... or  $Target* or $MPElement* I suppose...

    the parser in the Authoring Console even checks those expressions in script lines that are commented out for those...

  • I tested with $Data*, $Target* and $Config*, and only found that $Data* caused problems.  I didn't test with $MPElement*.