The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ScriptBlock.GetPowerShell Method (Object[])


Updated: April 27, 2016

Applies To: Windows PowerShell

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)

public PowerShell GetPowerShell(
	params object[] args


Type: System.Object[]

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

Type: System.Management.Automation.PowerShell

A PowerShell that represents the pipeline of the script block.

Exception Condition

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


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


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()

Return to top

Community Additions