Friday, May 6, 2011

Blog Post: Powershell Scripts - Illegal Variable Name

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*.

Busy Philipps Thora Birch Jennifer Garner Poppy Montgomery Evangeline Lilly

No comments:

Post a Comment