Adapter request and response for the PowerShell adapter

The PowerShell actor adapter sends commands to PowerShell and receives responses and results from the CLI of PowerShell. The PowerShell actor adapter supports the following Microsoft Windows PowerShell versions:

  • 1.0
  • 2.0
  • 3.0
  • 4.0

Notes

  • To configure an adapter request to communicate with the host computer that is not defined in the adapter configuration, you can designate a dynamic target by assigning values for the required configuration elements. These elements work as a set. You cannot retrieve partial information from the configuration node. 
  • You can omit the <targets> block from the adapter request. In the absence of a <targets> block, the default target from the adapter configuration is used. 
  • To override the configuration properties in the adapter configuration, include the target, user name, and password elements in the request.
  • WHAT'S NEW IN 20.17.01 You can specify <enable-psremoting> and <enable-psremoting-session> elements to run a list of multiple commands on a remote session. Only commands that are executed independently and do not return a PowerShell prompt are supported by the adapter. For more information, see Multiple commands in a remote session.

The following table describes the elements of the PowerShell adapter request.

Elements of the PowerShell adapter request

Element

Definition

Required

<targets>

Contains the <target> elements

No

<target>

Used to reference a target in the request

If the target element is not defined, the default target in the adapter configuration is used.

No

<host>

Contains the host name or the IP address of the remote or local computer

This element is required for defining a dynamic target computer.

No

<user-name>

Contains the user name to be used for authentication on the remote host computer

You must have administrative roles and privileges on the remote host computer. Your environment determines whether this element is required.

Conditional; required to define a dynamic target computer

<password>

Contains the password corresponding to the specified user name for authentication on the remote host computer

Your environment determines whether this element is required.

Valid values: Base64, Plain (default)

Note

This element can contain an encryption-type attribute to indicate whether the password provided is encrypted. You can provide special characters in the password such as $, *, &, {, }, and so on.

Conditional; required to define a dynamic target computer

<powershell-version>

Specifies the version of Microsoft Windows PowerShell on which the command is to be executed

DEPRECATED

Warning

With this release, the <powershell-version> element is deprecated. You no longer require to specify the Powershell version to run remote commands by using the PowerShell adapter. Commands are run by using Windows PowerShell available at the target system or the local system path.

No

<powershell-consolefile>

Specifies the PowerShell console file to be loaded

No

<character-set>

Specifies the supporting CharSet

Also called character set, it includes identifiers describing a series of universal characters.

Note

The locale and character set of the target computer must be compatible with the character set provided in the <character-set> element to get the desired results.

No

<use-userprofile>

Determines whether the user profile is to be loaded

Valid values: true, false

No

<commands>

NEW IN 20.17.01

Specifies an XML document that contains the list of commands to be executed on a remote server in a single session

Note

If you are specifying <commands>, you must not specify anything for the <command> element. The <commands> element can only be used for running commands in a PS remoting session mode, when <enable-psremoting> and <enable-psremoting-session> is specified as true.

The following figure shows a sample <commands> element used in the PowerShell adapter request

 <commands>
        <command><![CDATA[hostname]]></command>
        <command continue-on-failure="false"><![CDATA[whoami]]></command>
        <command continue-on-failure="true" ignore-exit-code="true">
<![CDATA[$myVariable = 'print session variable' ]]></command>
       <command ignore-exit-code="false">write-output $myVariable</command>
   </commands>


No

<command>

Contains the PowerShell command to be executed

No

<enable-psremoting>

Specifies whether to enable the remoting feature of PowerShell

Valid values: true, false (default)

No; required only if you want to run PowerShell commands on a remote server

<enable-psremoting-session>

NEW IN 20.17.01

Specifies whether to execute multiple commands in the same session

Valid values: true, false (default)

If specified as true, the PowerShell adapter executes multiple commands in the same session on a remote server. To run multiple commands in the same session, you must specify <enable-psremoting-session> as a child element of the <target> element and the <enable-psremoting> element must be set to true.

Only commands that are executed independently and do not return a PowerShell prompt are supported by the adapter.

For more information, see Sample adapter request when the <enable-psremoting-session> is set to true.

No

<logon-with-user-credentials>

Starts a service on the remote computer

  • Set <logon-with-user-credentials> to true to start the remote service using the credentials specified in the adapter configuration.
  • Set <logon-with-user-credentials> to false, to start the remote service using the SYSTEM credentials on the remote server.

    Valid values: true, false (default)

    Note

    To start a service on the remote computer, you must set the rights for the user name specified in <user-name> to Log on as a service. Use the Microsoft Windows Local Security Policy tool to set the user name rights.

No

<impersonate-user>

Specifies whether to enable the user impersonation and allow the specified user to execute tasks by using the security context of another user (For example, BAO service running under a user account)

For example, a service running as LocalSystem could access network resources by impersonating a specific user account. This account would have been configured with the necessary permissions to access a network resource, something the service would not be able to do otherwise.For more information about how user impersonation works, see Impersonation

If set to true, the Service Control Manager (SCM) API is invoked with the user specified in the adapter request or configuration.

By default, the xCmd utility runs under the security context of the BAO service running under a user account. When we specify <impersonate-user> as true, the SCM API is invoked with the user specified in the adapter request or configuration.

Valid values: true, false (default)

No
<service-launch-mode>

Specifies the mode to launch the xCommand service on a remote system

By default, the xCommand utility is launched on 32-bit mode.

Valid value: 64bit

Specify 64bit only if you want to launch the xCommand service on a 64-bit image mode on the target system.

BMC recommends that you do not specify any value if 64-bit is not required as it can affect the time taken for the request to execute.

No
<redirect-error-to-success-output-stream>

Specifies whether to redirect the command output error stream to the success output stream

Valid values: true, false (default)

When specified as true, all PowerShell commands are redirected to the success output stream.

The PowerShell adapter uses the xCMD utility to connect to the Windows System remotely to perform PowerShell commands. Since the xCMD utility only consumes output streams, it fails to process the data written on error streams and the actual output is not processed by the xCMD utility and reports an error. This problem occurs while executing the PowerShell Module cmd-lets version 3.0 and later.

No

The following figure shows an XML sample for the PowerShell actor adapter request. 

XML sample of the PowerShell adapter request

<powershell-request>
   <targets>
    <target>
      <host></host>
      <user-name></user-name>
      <password encryption-type="">testpass</password>
      <character-set>gb18030</character-set>
      <powershell-consolefile>pshell.psc1</powershell-consolefile>
      <use-userprofile>true</use-userprofile>
    </target>
   </targets>
  <commands>
    <command></command>
    <command></command>
  </commands>
</powershell-request>

Note

If the command length is more than 1000 characters, save the command text as a script file. Provide the complete path and the name of the script file as the value for the <command> element in the adapter request.

For example,
<commands>
<command working-dir="C:\temp1\with space">C:\abc\OSProperties.ps1</command>
</commands>

The following figure shows the adapter request for the PowerShell adapter, where multiple PowerShell commands are used in a single adapter request. Use the adapter request XML when you create a custom process by using the Call Adapter activity in BMC Atrium Orchestrator Development Studio.

XML sample of the PowerShell adapter request

<powershell-request>
    <commands>
       <command>get-alert -criteria {Name LIKE 'Performance%' }</command>
       <command>get-service</command>
    </commands>
</powershell-request>


The following figure shows an example of the Powershell adapter request with the get-service PowerShell command.
XML sample of the PowerShell adapter request with get-service command

<powershell-request>
   <targets>
    <target>
      <host>computer2</host>
      <user-name>testuser</user-name>
      <password encryption-type="Plain">testpass</password>
      <character-set>gb18030</character-set>
      <powershell-consolefile>pshell.psc1</powershell-consolefile>
      <use-userprofile>true</use-userprofile>
    </target>
   </targets>
   <commands>
    <command>get-service</command>
   </commands>
</powershell-request>


The following figure shows an XML sample for the PowerShell adapter request with relative path. Use the adapter request XML when you create a custom process by using the Call Adapter activity in BMC Atrium Orchestrator Development Studio.
XML sample of the PowerShell adapter request with relative path

<powershell-request>
  <commands>
    <command working-dir=" D:\scripts">./SampleScript.ps1</command>
    <command working-dir=" D:\scripts">./OSProperties.ps1</command>
  </commands>
</powershell-request>


The following figure shows an XML sample for the PowerShell adapter request with full path. Use the adapter request XML when you create a custom process by using the Call Adapter activity in BMC Atrium Orchestrator Development Studio.

XML sample of the PowerShell adapter request with full path

<powershell-request>
  <commands>
    <command>D:\scripts\SampleScript.ps1</command>
    <command>D:\scripts\OSProperties.ps1</command>
  </commands>
</powershell-request>

The following figure shows an XML sample for the PowerShell actor adapter request when the remoting feature is enabled.
XML sample of the PowerShell adapter request when the remoting feature is enabled

<powershell-request>
        <targets>
          <target>
          <host>10.128.249.47</host>
          <user-name>bmcadmin</user-name>
          <password encryption-type="Plain">Global@123</password>
          <enable-psremoting>true</enable-psremoting>
        </target>
        </targets>
          <commands>
             <command>ipconfig</command>
             .
             .
             .
          </commands>
</powershell-request> 


The following figure shows an XML sample for the PowerShell actor adapter request when <logon-with-user-credentials> is set to true.

XML sample of the PowerShell adapter request when <logon-with-user-credentials> is set to true

<powershell-request>
  <targets>
     <target>
       <host>BMC-GLOBALLOGIC</host>
       <user-name>bmcadmin</user-name>
       <password>bmc123</password>
       <logon-with-user-credentials>true</logon-with-user-credentials>
    </target>
  </targets>
  <commands>
     <command>ipconfig</command>
  </commands>
</powershell-request> 

The PowerShell adapter response contains the result returned from an adapter request. The following figure shows an XML sample for the PowerShell adapter response with get-service PowerShell command.

XML sample of the PowerShell adapter response

 <powershell-output>
  <metadata>
   <status>success</status>
  </metadata>
   <targets-output>
   <target-output host = "10.128.248.76">
   <metadata>
    <os-id>Windows 2003</os-id>
    <os-version>5.2 Build 3790 Service Pack 2</os-version>
    <status>success</status>
   </metadata>
  <commands-output>
   <command-output>
    <metadata>
     <command>Get-Service</command>
     <line-count>170</line-count>
     <execution-milliseconds>7735</execution-milliseconds>
     <exit-code>0</exit-code>
     <status>success</status>
    </metadata>
  <output>
   <line index = "1">Copyright 2010 BMC Software Ltd, Version: 1.1</line>
   <line index = "2">Connecting to remote service...</line>
   <line index = "3">Connected to remote host.</line>
   <line index = "4">Status   Name               DisplayName</line>
   <line index = "5">------   ----               -----------</line>
***  command response ***
   <line index = "169">Stopped xmlprov Network Provisioning Service</line>
   <line index = "170">Remote application exited with code: 0</line>
  </output>
  </command-output>
 </commands-output>
  </target-output>
 </targets-output>
</powershell-output>

The following figure shows an XML sample for the PowerShell adapter response when the remoting feature is enabled in the adapter request.

XML sample of the PowerShell adapter response when the remoting feature is enabled

<powershell-output>
  <metadata>
    <status>success</status>
  </metadata>
  <targets-output>
   <target-output host="10.128.249.47">
    <metadata>
     <os-id>Windows XP</os-id>
     <os-version>5.1.2600</os-version>
     <status>success</status>
    </metadata>
    <commands-output>
     <command-output>
      <metadata>
       <command>ipconfig</command>
       <line-count>11</line-count>
       <execution-milliseconds>1492</execution-milliseconds>
       <exit-code>0</exit-code>
       <status>success</status>
     </metadata>
     <output>
      <line index="1">Windows IP Configuration</line>
      <line index="2">Ethernet adapter Local Area Connection:</line>
      <line index="3"> Connection-specific DNS Suffix . : bmc.com</line>
      <line index="4"> IP Address. . . . . . . . . . . . : 10.128.249.47</line>
      <line index="5"> Subnet Mask . . . . . . . . . . . : 255.255.254.0</line>
      <line index="6"> Default Gateway . . . . . . . . . : 10.128.248.1</line>
      <line index="7">Ethernet adapter...........:</line>
      <line index="8"> Connection-specific DNS Suffix . : </line>
      <line index="9"> IP Address. . . . . . . . . . . . : 0.0.0.0</line>
      <line index="10"> Subnet Mask . . . . . . . . . . . : 0.0.0.0</line>
      <line index="11"> Default Gateway . . . . . . . . . : </line>
     </output>
    </command-output>
   </commands-output>
  </target-output>
 </targets-output>
</powershell-output>

The following figure shows an XML sample for the PowerShell actor adapter response when <logon-with-user-credentials> is set to true.

XML sample of the PowerShell adapter response when <logon-with-user-credentials> is set to true

<powershell-output>
  <metadata>
    <status>success</status>
  </metadata>
  <targets-output>
    <target-output host="10.128.249.47">
      <metadata>
        <status>success</status>
      </metadata>
      <commands-output>
        <command-output>
          <metadata>
            <command>ipconfig</command>
            <line-count>15</line-count>
            <execution-milliseconds>32938</execution-milliseconds>
            <exit-code>0</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1">Copyright 2010 BMC Software Ltd, Version: 1.5 </line>
            <line index="2">Connecting to remote service...</line>
            <line index="3">Connected to remote host.</line>
            <line index="4">Windows IP Configuration</line>
            <line index="5">Ethernet adapter Local Area Connection:</line>
            <line index="6"> Connection-specific DNS Suffix . : bmc.com</line>
            <line index="7"> IP Address. . . . . . . . . . . . : 10.128.249.47</line>
            <line index="8"> Subnet Mask . . . . . . . . . . . : 255.255.254.0</line>
            <line index="9"> Default Gateway . . . . . . . . . : 10.128.248.1</line>
            <line index="10">Ethernet adapter {EDE30461-C964-4723-863B-AD7D4CFE4886}:</line>
            <line index="11"> Connection-specific DNS Suffix . : </line>
            <line index="12"> IP Address. . . . . . . . . . . . : 0.0.0.0</line>
            <line index="13"> Subnet Mask . . . . . . . . . . . : 0.0.0.0</line>
            <line index="14"> Default Gateway . . . . . . . . . : </line>
            <line index="15">Remote application exited with code: 0 </line>
          </output>
        </command-output>
      </commands-output>
    </target-output>
  </targets-output>
</powershell-output> 

The following figure shows an XML sample for the PowerShell actor adapter request when the <impersonate-user> is set to true.

XML sample for the PowerShell actor adapter request when the <impersonate-user> is set to true

<powershell-request>
    <targets>
      <target>
        <host>vm-w23-rds87</host>
        <userName>Domain_Name\User</userName>
        <password encryption-type="Plain">XXXXXXX</password>
        <impersonate-user>true</impersonate-user>
        <logon-with-user-credentials />
        <service-launch-mode />
        <character-set />
        <powershell-version>1.0</powershell-version>
      </target>
    </targets>
    <commands>
      <command>get-service</command>
    </commands>
</powershell-request>

The following figure shows an XML sample for the PowerShell actor adapter request when the <service-launch-mode> is 64-bit.

XML sample for the PowerShell actor adapter request when the <service-launch-mode> is 64-bit

<powershell-request>
    <targets>
      <target>
        <host>vm-w23-rds87</host>
        <userName>Domain_Name\User</userName>
        <password encryption-type="Plain">XXXXXXX</password>
        <impersonate-user>true</impersonate-user>
        <logon-with-user-credentials />
        <service-launch-mode>64bit</service-launch-mode>
        <character-set />
        <powershell-version>1.0</powershell-version>
      </target>
    </targets>
    <commands>
      <command timeout-secs="150">whoami</command>
    </commands>
  </powershell-request>

The following figure shows an XML sample for the PowerShell actor adapter request when the <enable-psremoting-session> is true. 

XML sample for the PowerShell actor adapter request when the <enable-psremoting-session> is true

<powershell-request>
      <targets>
        <target>
         <host>clm-XXXX-zzzzz.bmc.com</host>
         <userName>Admin</userName>
         <password>password</password>
         <enable-psremoting-session>true</enable-psremoting-session>
         <enable-psremoting>true</enable-psremoting>
         </target>
      </targets>
      <commands>
        <command><![CDATA[hostname]]></command>
        <command continue-on-failure="false"><![CDATA[whoami]]></command>
        <command continue-on-failure="true" ignore-exit-code="true"><![CDATA[$mytable = 'This is my test for variable in session' ]]></command>
       <command ignore-exit-code="false">write-output $mytable</command>
     </commands>
</powershell-request>

The following figure shows the sample adapter response for the request when the <enable-psremoting-session> is true.

Adapter response for the request when the <enable-psremoting-session> is true

<powershell-output>
  <metadata>
    <status>success</status>
  </metadata>
  <targets-output>
    <target-output host="clm-XXXX-zzzzz.bmc.com">
      <metadata>
        <status>success</status>
      </metadata>
      <commands-output>
        <command-output>
          <metadata>
            <command>hostname</command>
            <line-count>1</line-count>
            <execution-milliseconds>214</execution-milliseconds>
            <exit-code>0</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1">clm-XXXX-zzzzz</line>
          </output>
        </command-output>
        <command-output>
          <metadata>
            <command>whoami</command>
            <line-count>1</line-count>
            <execution-milliseconds>235</execution-milliseconds>
            <exit-code>0</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1">clm-XXXX-zzzzz\administrator</line>
          </output>
        </command-output>
        <command-output>
          <metadata>
            <command>$mytable = 'This is my test for variable in session' </command>
            <line-count>1</line-count>
            <execution-milliseconds>237</execution-milliseconds>
            <exit-code>9999</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1"></line>
          </output>
        </command-output>
        <command-output>
          <metadata>
            <command>write-output $mytable</command>
            <line-count>1</line-count>
            <execution-milliseconds>523</execution-milliseconds>
            <exit-code>0</exit-code>
            <status>success</status>
          </metadata>
          <output>
            <line index="1">This is my test for variable in session</line>
          </output>
        </command-output>
      </commands-output>
    </target-output>
  </targets-output>
</powershell-output>

The following figure shows the adapter response when the <enable-psremoting-session> is true but the adapter is unable to connect to a remote server. 

Adapter response when the <enable-psremoting-session> is true but the adapter is unable to connect to a remote server 

<powershell-output>
  <metadata>
    <status>success</status>
  </metadata>
  <targets-output>
    <target-output host="clm-XXXX-zzzzz.bmc.com">
      <metadata>
        <status>success</status>
      </metadata>
      <commands-output>
        <command-output>
          <metadata>
            <command>$s = Enter-PSSession -ComputerName clm-XXXX-zzzzz.bmc.com -credential $cred</command>
            <line-count>11</line-count>
            <execution-milliseconds>17953</execution-milliseconds>
            <exit-code>1</exit-code>
            <status>error</status>
            <error>Exit code indicates error</error>
          </metadata>
          <output>
            <line index="1">Enter-PSSession : Connecting to remote server clm-XXXX-zzzzz.bmc.com failed </line>
            <line index="2">with the following error message : Access is denied. For more information, see </line>
            <line index="3">the about_Remote_Troubleshooting Help topic.</line>
            <line index="4">At line:1 char:6</line>
            <line index="5">+ $s = Enter-PSSession -ComputerName clm-XXXX-zzzzz.bmc.com -credential </line>
            <line index="6">$cred;echo ...</line>
            <line index="7">+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</line>
            <line index="8">    + CategoryInfo          : InvalidArgument: (clm-XXXX-zzzzz.bmc.com:String) </line>
            <line index="9">    [Enter-PSSession], PSRemotingTransportException</line>
            <line index="10">    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed</line>
            <line index="11"> </line>
          </output>
        </command-output>
      </commands-output>
    </target-output>
  </targets-output>
</powershell-output>
Was this page helpful? Yes No Submitting... Thank you

Comments