Partager via


ScriptBlock.GetPowerShell Method

Definition

Overloads

GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

GetPowerShell(Dictionary<String,Object>, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Boolean, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

GetPowerShell(Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock.

GetPowerShell(Boolean, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, similar to the GetPowerShell() method. If the 'isTrustedInput' flag parameter is set to True, then the GetPowerShell() implementation supports extended conversion operations (such as replacing variable values with their current values) that might otherwise be unsafe if applied to untrusted input.

GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

public:
 System::Management::Automation::PowerShell ^ GetPowerShell(System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ variables, [Runtime::InteropServices::Out] System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ % usingVariables, ... cli::array <System::Object ^> ^ args);
public System.Management.Automation.PowerShell GetPowerShell (System.Collections.Generic.Dictionary<string,object> variables, out System.Collections.Generic.Dictionary<string,object> usingVariables, params object[] args);
member this.GetPowerShell : System.Collections.Generic.Dictionary<string, obj> * Dictionary * obj[] -> System.Management.Automation.PowerShell
Public Function GetPowerShell (variables As Dictionary(Of String, Object), ByRef usingVariables As Dictionary(Of String, Object), ParamArray args As Object()) As PowerShell

Parameters

variables
Dictionary<String,Object>

variables to be supplied as context to the ScriptBlock (providing values for variables explicitly requested by the 'using:' prefix.

usingVariables
Dictionary<String,Object>

key-value pairs from the

variables

that actually get used by the 'using:' prefix variables

args
Object[]

arguments for the ScriptBlock (providing values for variables used within the ScriptBlock); can be null

Returns

PowerShell object representing the pipeline contained in this ScriptBlock

Exceptions

Thrown when this ScriptBlock cannot be expressed as a PowerShell object. For example thrown when there is more than one statement, if there are undeclared variables, if redirection to a file is used.

Thrown when evaluation of command arguments results in an exception. Might depend on the value of $errorActionPreference variable. For example trying to translate the following ScriptBlock will result in this exception: $errorActionPreference = "stop"; $sb = { get-foo $( throw ) }; $sb.GetPowerShell()

Thrown when there is no ExecutionContext associated with this ScriptBlock object and no variables are supplied.

Applies to

GetPowerShell(Dictionary<String,Object>, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

public:
 System::Management::Automation::PowerShell ^ GetPowerShell(System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ variables, ... cli::array <System::Object ^> ^ args);
public System.Management.Automation.PowerShell GetPowerShell (System.Collections.Generic.Dictionary<string,object> variables, params object[] args);
member this.GetPowerShell : System.Collections.Generic.Dictionary<string, obj> * obj[] -> System.Management.Automation.PowerShell
Public Function GetPowerShell (variables As Dictionary(Of String, Object), ParamArray args As Object()) As PowerShell

Parameters

variables
Dictionary<String,Object>

variables to be supplied as context to the ScriptBlock (providing values for variables explicitly requested by the 'using:' prefix.

args
Object[]

arguments for the ScriptBlock (providing values for variables used within the ScriptBlock); can be null

Returns

PowerShell object representing the pipeline contained in this ScriptBlock

Exceptions

Thrown when this ScriptBlock cannot be expressed as a PowerShell object. For example thrown when there is more than one statement, if there are undeclared variables, if redirection to a file is used.

Thrown when evaluation of command arguments results in an exception. Might depend on the value of $errorActionPreference variable. For example trying to translate the following ScriptBlock will result in this exception: $errorActionPreference = "stop"; $sb = { get-foo $( throw ) }; $sb.GetPowerShell()

Thrown when there is no ExecutionContext associated with this ScriptBlock object and no variables are supplied.

Applies to

GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Boolean, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, using variables supplied in the dictionary.

public:
 System::Management::Automation::PowerShell ^ GetPowerShell(System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ variables, [Runtime::InteropServices::Out] System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ % usingVariables, bool isTrustedInput, ... cli::array <System::Object ^> ^ args);
public System.Management.Automation.PowerShell GetPowerShell (System.Collections.Generic.Dictionary<string,object> variables, out System.Collections.Generic.Dictionary<string,object> usingVariables, bool isTrustedInput, params object[] args);
member this.GetPowerShell : System.Collections.Generic.Dictionary<string, obj> * Dictionary * bool * obj[] -> System.Management.Automation.PowerShell
Public Function GetPowerShell (variables As Dictionary(Of String, Object), ByRef usingVariables As Dictionary(Of String, Object), isTrustedInput As Boolean, ParamArray args As Object()) As PowerShell

Parameters

variables
Dictionary<String,Object>

variables to be supplied as context to the ScriptBlock (providing values for variables explicitly requested by the 'using:' prefix.

usingVariables
Dictionary<String,Object>

key-value pairs from the

variables

that actually get used by the 'using:' prefix variables

isTrustedInput
Boolean

Specifies whether the scriptblock being converted comes from a trusted source. The default is False.

args
Object[]

arguments for the ScriptBlock (providing values for variables used within the ScriptBlock); can be null

Returns

PowerShell object representing the pipeline contained in this ScriptBlock

Exceptions

Thrown when this ScriptBlock cannot be expressed as a PowerShell object. For example thrown when there is more than one statement, if there are undeclared variables, if redirection to a file is used.

Thrown when evaluation of command arguments results in an exception. Might depend on the value of $errorActionPreference variable. For example trying to translate the following ScriptBlock will result in this exception: $errorActionPreference = "stop"; $sb = { get-foo $( throw ) }; $sb.GetPowerShell()

Thrown when there is no ExecutionContext associated with this ScriptBlock object and no variables are supplied.

Applies to

GetPowerShell(Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock.

public:
 System::Management::Automation::PowerShell ^ GetPowerShell(... cli::array <System::Object ^> ^ args);
public System.Management.Automation.PowerShell GetPowerShell (params object[] args);
member this.GetPowerShell : obj[] -> System.Management.Automation.PowerShell
Public Function GetPowerShell (ParamArray args As Object()) As PowerShell

Parameters

args
Object[]

arguments for the ScriptBlock (providing values for variables used within the ScriptBlock); can be null

Returns

PowerShell object representing the pipeline contained in this ScriptBlock

Exceptions

Thrown when this ScriptBlock cannot be expressed as a PowerShell object. For example thrown when there is more than one statement, if there are undeclared variables, if redirection to a file is used.

Thrown when evaluation of command arguments results in an exception. Might depend on the value of $errorActionPreference variable. For example trying to translate the following ScriptBlock will result in this exception: $errorActionPreference = "stop"; $sb = { get-foo $( throw ) }; $sb.GetPowerShell()

Thrown when there is no ExecutionContext associated with this ScriptBlock object.

Remarks

Some ScriptBlocks are too complicated to be converted into a PowerShell object. For those ScriptBlocks a ScriptBlockToPowerShellNotSupportedException is thrown.

ScriptBlock cannot be converted into a PowerShell object if - It contains more than one statement - It references variables undeclared in param(...) block - It uses redirection to a file - It uses dot sourcing - Command names can't be resolved (i.e. if an element of a pipeline is another scriptblock)

Declaration of variables in a param(...) block is enforced, because undeclared variables are assumed to be variables from a remoting server. Since we need to fully evaluate parameters of commands of a PowerShell object's we reject all variables references that refer to a variable from a remoting server.

Applies to

GetPowerShell(Boolean, Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock, similar to the GetPowerShell() method. If the 'isTrustedInput' flag parameter is set to True, then the GetPowerShell() implementation supports extended conversion operations (such as replacing variable values with their current values) that might otherwise be unsafe if applied to untrusted input.

public:
 System::Management::Automation::PowerShell ^ GetPowerShell(bool isTrustedInput, ... cli::array <System::Object ^> ^ args);
public System.Management.Automation.PowerShell GetPowerShell (bool isTrustedInput, params object[] args);
member this.GetPowerShell : bool * obj[] -> System.Management.Automation.PowerShell
Public Function GetPowerShell (isTrustedInput As Boolean, ParamArray args As Object()) As PowerShell

Parameters

isTrustedInput
Boolean

Specifies whether the scriptblock being converted comes from a trusted source. The default is False.

args
Object[]

arguments for the ScriptBlock (providing values for variables used within the ScriptBlock); can be null

Returns

Applies to