Problems passing a Boolean parameter to a PowerShell script.

Hello,

I'm trying to create a Diagnostic which leverages a PowerShell script (I've been working solely with VBScript thus far), hosted by the probe action module Microsoft.Windows.PowerShellProbe, and am having problems passing a boolean parameter to the script.  I have built the following Parameters section, build according to http://www.code4ward.net/main/Blog/tabid/70/EntryId/50/How-to-create-a-PowerShell-task-for-OpsMgr-using-the-Authoring-Console.aspx:

                <Parameters>
                  <Parameter>
                    <Name>TopN</Name>
                    <Value>$Config/TopN$</Value>
                  </Parameter>
                  <Parameter>
                    <Name>Debug</Name>
                    <Value>$Config/Debug$</Value>
                  </Parameter>
                </Parameters>

I'm having troubles forcing the Debug paramter to a boolean type in my PoSH script.  Here is my ProbeActionmodule's Configuration section:

        <Configuration>
          <xsd:element minOccurs="1" name="TopN" type="xsd:integer" />
          <xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer" />
          <xsd:element minOccurs="1" name="Debug" type="xsd:boolean" />
        </Configuration>

When I force the Debug parameter from within the PoSH script as follows, the task consistently returns No output available (despite the fact that the script runs as expected on its own):

Param(
 [int]$TopN,
 [bool]$Debug
)

The task only works when I define the parameter as a string, as follows:

Param(
 [int]$TopN,
 $Debug
)

Updating the Debug parameter by adding a '$' in front of the $Config/Debug$ variable (in order to accomodate PoSH's boolean value requirement (i.e. $true | $false)), as shown here, does not resolve the problem:

                  <Parameter>
                    <Name>Debug</Name>
                    <Value>$$Config/Debug$</Value>
                  </Parameter>

Does anyone have any suggestions?

T

July 26th, 2013 2:32pm

You should just be able to pass true or false (with no $) into the script.  PowerShell converts the string to a Boolean.  There is an example of a Debug parameter on a PowerShell script in my Stores sample MP you can refer to.
Free Windows Admin Tool Kit Click here and download it now
August 3rd, 2013 5:08pm

Hi,

alternatively, you can pass 1 or 0. Powershell should convert it correctly as well. 

August 4th, 2013 1:37am

Hello Brian,

Being a purist, I find it unfortunate that the Microsoft.Windows.PowerShellProbe probe action module does not support the type casting of an input parameter as a [bool].  Weird that it works fine with [int].  Ive opened an incident with Premier to see if this can be fixed.

Thanks for the pointer to the Stores Sample MP.

Regards,

Free Windows Admin Tool Kit Click here and download it now
August 20th, 2013 6:52pm

Hello Brian,

Being a purist, I find it unfortunate that the Microsoft.Windows.PowerShellProbe probe action module does not support the type casting of an input parameter as a [bool].  Weird that it works fine with [int].  Ive opened an incident with Premier to see if this can be fixed.

Thanks for the pointer to the Stores Sample MP.

Regards,

September 1st, 2015 10:15pm

After a little digging, it seems the root of the problem is in the schema type used in Powershell probe modules. This can be viewed in the Windows Library. Notice the value will always be type cast as String. This could be fixed by adding a choice for value types in this schema. Maybe this is something Microsoft will consider?

<SchemaType ID="Microsoft.Windows.PowerShellSchema" Accessibility="Public">
  <xsd:complexType name="NamedParametersType">
    <xsd:sequence>
      <xsd:element name="Parameter" minOccurs="0" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="Name" type="xsd:ID" />
            <xsd:element name="Value" type="xsd:string" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="SnapInsType">
    <xsd:sequence>
      <xsd:element name="SnapIn" minOccurs="0" maxOccurs="unbounded" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="NonNullString">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1" />
    </xsd:restriction>
  </xsd:simpleType>
</SchemaType>

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 12:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics