PowerShell.AddScript PowerShell.AddScript PowerShell.AddScript Method

Definition

Overloads

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

A string representing a script.

Returns

A PowerShell instance with command added.

Exceptions

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread-safe.

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

A string representing a script.

useLocalScope
Boolean Boolean Boolean

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

Returns

A PowerShell instance with command added.

Exceptions

Powershell instance cannot be changed in its current state.

Remarks

This method is not thread-safe.

Applies to