Udostępnij za pośrednictwem


CommandInvocationIntrinsics.InvokeScript Method

Definition

Overloads

InvokeScript(String)

Executes a piece of text as a script synchronously in the caller's session state. The given text will be executed in a child scope rather than dot-sourced.

InvokeScript(String, Object[])

Executes a piece of text as a script synchronously in the caller's session state. The given text will be executed in a child scope rather than dot-sourced.

InvokeScript(SessionState, ScriptBlock, Object[])

Executes a given scriptblock synchronously in the given session state. The scriptblock will be executed in the calling scope (dot-sourced) rather than in a new child scope.

InvokeScript(Boolean, ScriptBlock, IList, Object[])

Invoke a scriptblock in the current runspace, controlling if it gets a new scope.

InvokeScript(String, Boolean, PipelineResultTypes, IList, Object[])

Executes a piece of text as a script synchronously using the options provided.

InvokeScript(String)

Executes a piece of text as a script synchronously in the caller's session state. The given text will be executed in a child scope rather than dot-sourced.

public:
 System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeScript(System::String ^ script);
public System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeScript (string script);
member this.InvokeScript : string -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Function InvokeScript (script As String) As Collection(Of PSObject)

Parameters

script
String

The script text to evaluate.

Returns

A collection of PSObjects generated by the script. Never null, but may be empty.

Exceptions

Thrown if there was a parsing error in the script.

Represents a script-level exception.

Applies to

InvokeScript(String, Object[])

Executes a piece of text as a script synchronously in the caller's session state. The given text will be executed in a child scope rather than dot-sourced.

public:
 System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeScript(System::String ^ script, ... cli::array <System::Object ^> ^ args);
public System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeScript (string script, params object[] args);
member this.InvokeScript : string * obj[] -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Function InvokeScript (script As String, ParamArray args As Object()) As Collection(Of PSObject)

Parameters

script
String

The script text to evaluate.

args
Object[]

The arguments to the script, available as $args.

Returns

A collection of PSObjects generated by the script. Never null, but may be empty.

Exceptions

Thrown if there was a parsing error in the script.

Represents a script-level exception.

Applies to

InvokeScript(SessionState, ScriptBlock, Object[])

Executes a given scriptblock synchronously in the given session state. The scriptblock will be executed in the calling scope (dot-sourced) rather than in a new child scope.

public:
 System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeScript(System::Management::Automation::SessionState ^ sessionState, System::Management::Automation::ScriptBlock ^ scriptBlock, ... cli::array <System::Object ^> ^ args);
public System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeScript (System.Management.Automation.SessionState sessionState, System.Management.Automation.ScriptBlock scriptBlock, params object[] args);
member this.InvokeScript : System.Management.Automation.SessionState * System.Management.Automation.ScriptBlock * obj[] -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Function InvokeScript (sessionState As SessionState, scriptBlock As ScriptBlock, ParamArray args As Object()) As Collection(Of PSObject)

Parameters

sessionState
SessionState

The session state in which to execute the scriptblock.

scriptBlock
ScriptBlock

The scriptblock to execute.

args
Object[]

The arguments to the scriptblock, available as $args.

Returns

A collection of the PSObjects emitted by the executing scriptblock. Never null, but may be empty.

Applies to

InvokeScript(Boolean, ScriptBlock, IList, Object[])

Invoke a scriptblock in the current runspace, controlling if it gets a new scope.

public:
 System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeScript(bool useLocalScope, System::Management::Automation::ScriptBlock ^ scriptBlock, System::Collections::IList ^ input, ... cli::array <System::Object ^> ^ args);
public System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeScript (bool useLocalScope, System.Management.Automation.ScriptBlock scriptBlock, System.Collections.IList input, params object[] args);
member this.InvokeScript : bool * System.Management.Automation.ScriptBlock * System.Collections.IList * obj[] -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Function InvokeScript (useLocalScope As Boolean, scriptBlock As ScriptBlock, input As IList, ParamArray args As Object()) As Collection(Of PSObject)

Parameters

useLocalScope
Boolean

If true, executes the scriptblock in a new child scope, otherwise the scriptblock is dot-sourced into the calling scope.

scriptBlock
ScriptBlock

The scriptblock to execute.

input
IList

Optional input to the command.

args
Object[]

Arguments to pass to the scriptblock.

Returns

A collection of the PSObjects generated by executing the script. Never null, but may be empty.

Applies to

InvokeScript(String, Boolean, PipelineResultTypes, IList, Object[])

Executes a piece of text as a script synchronously using the options provided.

public:
 System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject ^> ^ InvokeScript(System::String ^ script, bool useNewScope, System::Management::Automation::Runspaces::PipelineResultTypes writeToPipeline, System::Collections::IList ^ input, ... cli::array <System::Object ^> ^ args);
public System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> InvokeScript (string script, bool useNewScope, System.Management.Automation.Runspaces.PipelineResultTypes writeToPipeline, System.Collections.IList input, params object[] args);
member this.InvokeScript : string * bool * System.Management.Automation.Runspaces.PipelineResultTypes * System.Collections.IList * obj[] -> System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject>
Public Function InvokeScript (script As String, useNewScope As Boolean, writeToPipeline As PipelineResultTypes, input As IList, ParamArray args As Object()) As Collection(Of PSObject)

Parameters

script
String

The script to evaluate.

useNewScope
Boolean

If true, evaluate the script in its own scope. If false, the script will be evaluated in the current scope i.e. it will be dot-sourced.

writeToPipeline
PipelineResultTypes

If set to Output, all output will be streamed to the output pipe of the calling cmdlet. If set to None, the result will be returned to the caller as a collection of PSObjects. No other flags are supported at this time and will result in an exception if used.

input
IList

The list of objects to use as input to the script.

args
Object[]

The array of arguments to the command, available as $args.

Returns

A collection of PSObjects generated by the script. This will be empty if output was redirected. Never null.

Exceptions

Thrown if there was a parsing error in the script.

Represents a script-level exception.

Thrown if any redirect other than output is attempted.

Applies to