Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

PowerShell.AddScript Method

Definition

Namespace:
System.Management.Automation
Assembly:
System.Management.Automation.dll
Package:
Microsoft.PowerShell.5.1.ReferenceAssemblies v1.0.0
Package:
System.Management.Automation v7.4.15
Package:
System.Management.Automation v7.5.6
Package:
System.Management.Automation v7.6.1

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
AddScript(String)

Add a piece of script to construct a command pipeline. For example, to construct a command string "Get-Process | ForEach-Object { $_.Name }"

PowerShell shell = PowerShell.Create()
 .AddScript("Get-Process | ForEach-Object { $_.Name }");
AddScript(String, Boolean)

Add a piece of script to construct a command pipeline. For example, to construct a command string "Get-Process | ForEach-Object { $_.Name }"

PowerShell shell = PowerShell.Create()
 .AddScript("Get-Process | ForEach-Object { $_.Name }", true);

AddScript(String)

Add a piece of script to construct a command pipeline. For example, to construct a command string "Get-Process | ForEach-Object { $_.Name }"

PowerShell shell = PowerShell.Create()
 .AddScript("Get-Process | ForEach-Object { $_.Name }");
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-Object { $_.Name }"

PowerShell shell = PowerShell.Create()
 .AddScript("Get-Process | ForEach-Object { $_.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