PowerShell

public class PShell

You can use the PowerShell adapter to run your PowerShell scripts and get the corresponding output or errors.

 Methods

void AddScript(string code)

Add a script code

void SetParameter(string name, object value)

Set a parameter with the specified name and its value

bool Execute()

Execute a PowerShell instance

bool HasOutput()

Indicates whether there was an output

List<object> GetOutput()

Get a list with the output

bool HasError()

Indicates whether there was an error

List<object> GetErrors()

Get a list of errors that have occured

Example

This example gives you information about your computer.

import clr
clr.AddReferenceToFileAndPath(Session.GetAdapterPath("IYOPRO.POWERSHELL"))
from IYOPROPsAdapter import PShell

code = r'''
param
(
   [string]$Computer = XXX
)
Get-Wmiobject -computername $Computer win32_computersystem
'''
code = code.Replace("XXX", "\".\"")

shell = PShell()
shell.AddScript(code)

shell.SetParameter("Computer", "<device name>")

ok = shell.Execute()
results = shell.GetOutput()
errors = shell.GetErrors()
if results.Count > 0:
   o = results[0]
   print(o.SystemType)
   print(o.BootupState)
   print(o.Manufacturer)
   print(o.Model)

if errors.Count>0:
   o = errors[0]
   print(o.Exception.Message)