PowerShell.AddScript Method

Definition

Overloads

AddScript(String)

Add a piece of script to construct a command pipeline. For example, to construct a command string "get-process | foreach { $_.Name }"


                    PowerShell shell = PowerShell.Create("get-process").
                                                AddCommand("foreach { $_.Name }", true);
                
AddScript(String, Boolean)

Add a piece of script to construct a command pipeline. For example, to construct a command string "get-process | foreach { $_.Name }"


                    PowerShell shell = PowerShell.Create("get-process").
                                                AddCommand("foreach { $_.Name }", true);
                

AddScript(String)

Add a piece of script to construct a command pipeline. For example, to construct a command string "get-process | foreach { $_.Name }"


                    PowerShell shell = PowerShell.Create("get-process").
                                                AddCommand("foreach { $_.Name }", true);
                
public System.Management.Automation.PowerShell AddScript (string script);
Parameters
script
String

A string representing a script.

Returns

A PowerShell instance with command added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread-safe.

AddScript(String, Boolean)

Add a piece of script to construct a command pipeline. For example, to construct a command string "get-process | foreach { $_.Name }"


                    PowerShell shell = PowerShell.Create("get-process").
                                                AddCommand("foreach { $_.Name }", true);
                
public System.Management.Automation.PowerShell AddScript (string script, bool useLocalScope);
Parameters
script
String

A string representing a script.

useLocalScope
Boolean

if true local scope is used to run the script command.

Returns

A PowerShell instance with command added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

Object is disposed.

Remarks

This method is not thread-safe.