Management pack variables

I was having a problem importing a custom mp because the PowerShell discovery script I'd written had the reserved mp variable $Data in it. For background, the script queried a SQL table and the results populated a SCOM group.

This was the error during import:

Error 1:
Found error in 1|TestA.SQL.Monitoring|1.0.0.0|SQL.Discovery.AgPrimaryDb/DS|| with message:
The configuration specified for Module DS is not valid.
: Incorrect expression specified: $DatabaseReplica] ad
on ar.MachineName_EA844CA4_B2CD_69E3_D8A9_C2E4489C53C7 = ad.MachineName_EA844CA4_B2CD_69E3_D8A9_C2E4489C53C7
AND ar.AvailabilityGroupName_2B65F5C7_DE13_BC25_C1EB_AA53047BB141=ad.AvailabilityGroupName_BE1A08AB_595A_3684_51F5_BDA703BC96C9
where ar.Role_52418D34_8CEA_2508_880C_DE9B8EE7DAB2 = 'Primary'"
<# FOR TESTING
#. 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$

By pure coincidence this was caused by the SQL query in my PowerShell script that just happened to have a SQL view with the word $Data in it: 

$ScomQuery="SELECT distinct ad.MachineName_EA844CA4_B2CD_69E3_D8A9_C2E4489C53C7 as Server
, ad.InstanceName_2CC762EA_9008_8DED_CEEA_C0A731372EA8 as Instance
, ad.DisplayName as DisplayName
, ad.AvailabilityReplicaId_6271191B_CCD9_7A8B_ECA3_17F409F1C332
, ad.AvailabilityDatabaseName_4400632F_8F79_864A_A1FD_5ACF68FB111A as DbName
FROM OperationsManager.[dbo].[MTV_Microsoft`$SQLServer`$Windows`$AvailabilityReplica] ar
inner join [OperationsManager].[dbo].[MTV_Microsoft`$SQLServer`$Windows`$DatabaseReplica] ad
on ar.MachineName_EA844CA4_B2CD_69E3_D8A9_C2E4489C53C7 = ad.MachineName_EA844CA4_B2CD_69E3_D8A9_C2E4489C53C7
AND ar.AvailabilityGroupName_2B65F5C7_DE13_BC25_C1EB_AA53047BB141=ad.AvailabilityGroupName_BE1A08AB_595A_3684_51F5_BDA703BC96C9
where ar.Role_52418D34_8CEA_2508_880C_DE9B8EE7DAB2 = 'Primary'"

A work around was to create a new view in the OperationsManager database (which is a no-no) without the '$' symbol and the mp imported. Still looking for a better solution to this.

Some useful info on mp variables here.

Comments