ScriptBlock.GetPowerShell Method (Object[])

Returns a PowerShell object that represents the pipeline of the script block. This method is introduced in Windows PowerShell 2.0.


Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation.dll)

'Usage
Dim instance As ScriptBlock
Dim args As Object()
Dim returnValue As PowerShell

returnValue = instance.GetPowerShell(args)

public PowerShell GetPowerShell (
	params Object[] args
)
public PowerShell GetPowerShell (
	Object[] args
)
public function GetPowerShell (
	... args : Object[]
) : PowerShell

Parameters

args

An array of objects that represent the arguments for this script block (providing values for variables that are used within the script block). This parameter can be null.

Return Value

A PowerShell that represents the pipeline of the script block.

Exception typeCondition
ScriptBlockToPowerShellNotSupportedException

The script block cannot be expressed as a PowerShell object. See Remarks for more information.

RuntimeException

An error occurred while evaluating the script block arguments. See Remarks for more information.

InvalidOperationException

There is no execution context associated with the ScriptBlock object.

Some script blocks are too complicated to be converted into PowerShell objects. For those script blocks, a ScriptBlockToPowerShellNotSupportedException is thrown. Script blocks cannot be converted when any of the following conditions exist.

  • The script block contains more than one statement.

  • The script block references variables undeclared in a Param block.

  • The script block uses redirection to a file.

  • The script block uses dot sourcing.

  • The script block contains command names that cannot be resolved, such as when an element of a pipeline is another script block.

The RuntimeException exception is thrown when an error occurs while evaluating command arguments. When the exception is thrown may depend on the value of $errorActionPreference variable. For example, trying to translate the following script block will result in this exception:

$errorActionPreference = "stop"; $sb = { get-abc $( throw ) }; $sb.GetPowerShell()


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

 

Target Platforms

Windows Developer Preview, Windows Server Developer Preview

Send comments about this topic to Microsoft.
Show:
© 2014 Microsoft