[BUG] VSAE with a PowerShell $Data parameter

27 May

Hi,

This time for a short post on a ‘possible’ bug i detected in VSAE

Problem:

You create a PowerShell script and want to include this script using the $includeFileContent/<script_name>$ tag.

For example

<ProbeAction
ID=Probe
TypeID=Windows!Microsoft.Windows.PowerShellProbe
RunAs=SystemCenter!Microsoft.SystemCenter.DatabaseWriteActionAccount>

<ScriptName>FixTopNQuery.ps1</ScriptName>

<ScriptBody>$IncludeFileContent/FixTopNQuery.ps1$</ScriptBody>

<TimeoutSeconds>300</TimeoutSeconds>

<StrictErrorHandling>true</StrictErrorHandling>

</ProbeAction>

(Added a screenshot below)

The FixTopNQuery.ps1 is a PS script added to the project as “Embedded Resource”.

Now you compile the project and you get a compile error:

Error    1176    The configuration specified for Module Probe is not valid.

: Incorrect expression specified: $DataSet=New-Object System.Data.DataSet

. Unable to resolve this expression. Check the 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$

(Path = OpsLogix.IMP.Oracle.Dashboards.Task.FixTopNQuery/Probe)    C:\Program Files (x86)\MSBuild\Microsoft\VSAC\Microsoft.SystemCenter.OperationsManager.targets    255    6    Dashboards

(Added a screenshot below)


Hmmm.. Why ?

 

Analyze

After a lot of error and retry I found out that the problem is in the included powershell script. And exactly in this line below:

$DataSet=New-Object System.Data.DataSet

Hmm I hear you thinking, what’s wrong with this statement? That exactly what I was thinking…. But when I change the parameter name the compile was successful…

 

Solution

Do not start a parameter name with $Data in the powershell script. It looks like it’s a reserved word in VSAE.

 

I will share this issue also with the VSAA product team.

Happy Scomming

Michel Kamp

Advertisements

12 Responses to “[BUG] VSAE with a PowerShell $Data parameter”

  1. Alex June 2, 2014 at 09:39 #

    Just to add, the very ancient issue despite never described.
    it’s not only a Powershell issue, if it was a vb script we could the the same, as example msg=”$data1″ in a script body. So it’s most likely a reserved word as you suggested.

    • Michel Kamp June 2, 2014 at 09:44 #

      I Alex,
      Thanks for the notice also.

      I already contacted the product team on this case. let’s see if they can address this..

      Thanks
      Michel

      • Alex June 2, 2014 at 09:52 #

        OK, it’s interesting what they will say, I tried to report this bug to MS staff two years ago (In the days of VSAE 2010), nothing has changed))). So MS should not analyse scripts for words starting with $data, $mpelement or so.

      • Michel Kamp June 2, 2014 at 10:10 #

        Also a nice side effect is that I now know that i haven’t used parameters beginning with Data the last 3 years 😉

        Michel

  2. bradc September 2, 2014 at 03:09 #

    if you have no choice, e.g. if you’re doing certain oracle queries, you can try this
    $x=’select log_mode from v$dat’
    $y=’abase;’
    $CommandText=$x+$y

    • Michel Kamp September 5, 2014 at 06:53 #

      hi that could indeed be a work around. Thank for sharing.
      michel

  3. Dziugas August 27, 2015 at 07:12 #

    Thank you!

  4. Gary Pendlebury February 17, 2017 at 13:22 #

    It seems crazy that this is still a bug, but there’s a workaround. Instead of

    $DataSet = New-Object System.Data.DataSet

    Use:
    Set-Variable DataSet (New-Object System.Data.DataSet)
    And to access:
    Get-Variable DataSet -ValueOnly

    Care must be taken, however, to ensure that the value is unboxed; e.g. this will always return a value of 1:
    (Get-Variable SomeValues -ValueOnly | measure).Count
    Instead, to obtain the count, use:
    ((Get-Variable SomeValues -ValueOnly) | measure).Count

    • Michel Kamp February 23, 2017 at 21:12 #

      Yes correct. However just take a other name has less code and easier 😬

      • Gary Pendlebury February 27, 2017 at 10:03 #

        Agreed! Sometimes I need to be more flexible. In the end, I just went with renaming the variables from $Data$ to $_Data.

Trackbacks/Pingbacks

  1. SCOM link - IT Consult - September 1, 2016

    […] VSAE with a PowerShell $Data parameter […]

  2. Problem with variable names starting with “Data” | Get-BlogPost - February 17, 2017

    […] is a known bug in SCOM, whereby PowerShell scripts that are embedded in rules (i.e. where the script is visible in […]

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

%d bloggers like this: