Delen via


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(System::String ^ script);
public System.Management.Automation.PowerShell AddScript (string script);
member this.AddScript : string -> System.Management.Automation.PowerShell
Public Function AddScript (script As String) As PowerShell

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.

Applies to

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(System::String ^ script, bool useLocalScope);
public System.Management.Automation.PowerShell AddScript (string script, bool useLocalScope);
member this.AddScript : string * bool -> System.Management.Automation.PowerShell
Public Function AddScript (script As String, useLocalScope As Boolean) As PowerShell

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.

Applies to