Multiple commands in a remote session

Using the <enable-psremoting-session> element, PowerShell adapter can now run a list of multiple commands in a single session on a remote server by using the PS remoting mode.

Use the <enable-psremoting-session> element with the <enable-psremoting> element. You must specify the <enable-psremoting-session> element in the adapter request as a child element of the <target> element. For more information on sample adapter request and response, see Adapter request and response for the PowerShell adapter.

Note

Only commands that are executed independently and do not return a PowerShell prompt (commands that do not ask for a user input after execution of a command or open other shell or prompt) are supported currently. For example, DiskPart commands cannot be run by using the PowerShell adapter.


The following command attributes are supported by the adapter when you use the <enable-psremoting-session> element:

  • <ignore-response>
  • <continue-on-failure>
  • <timeout-secs>
  • <ignore-exit-code>

Warning

Do not specify <prompt> attribute for any of the commands.

The following command is invalid:

<command prompt="abc"><![CDATA[hostname]]></command>

In a remote session, the following features are not supported when you use the <enable-psremoting-session> element:

The following figure shows a sample XML adapter request for the PowerShell adapter by using the <enable-psremoting-session> element.

Sample XML adapter request for the PowerShell adapter by using the <enable-psremoting-session> element

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

Related topic

Adapter request and response for the PowerShell adapter

Was this page helpful? Yes No Submitting... Thank you

Comments