Share via


PSCommand.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 }"

PSCommand command = new PSCommand("get-process")
    .AddScript("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 }"

PSCommand command = new PSCommand("get-process")
    .AddScript("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 }"

PSCommand command = new PSCommand("get-process")
    .AddScript("foreach { $_.Name }", true);
public:
 System::Management::Automation::PSCommand ^ AddScript(System::String ^ script);
public System.Management.Automation.PSCommand AddScript (string script);
member this.AddScript : string -> System.Management.Automation.PSCommand
Public Function AddScript (script As String) As PSCommand

Parameters

script
String

A string representing the script.

Returns

A PSCommand instance with script added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

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

PSCommand command = new PSCommand("get-process")
    .AddScript("foreach { $_.Name }", true);
public:
 System::Management::Automation::PSCommand ^ AddScript(System::String ^ script, bool useLocalScope);
public System.Management.Automation.PSCommand AddScript (string script, bool useLocalScope);
member this.AddScript : string * bool -> System.Management.Automation.PSCommand
Public Function AddScript (script As String, useLocalScope As Boolean) As PSCommand

Parameters

script
String

A string representing the script.

useLocalScope
Boolean

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

Returns

A PSCommand instance with script added.

Exceptions

command is null.

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread-safe.

Applies to