ScriptBlock ScriptBlock ScriptBlock Class

Definition

An object representing a pre-compiled block of powershell script.

public class ScriptBlock : System.Runtime.Serialization.ISerializable
type ScriptBlock = class
    interface ISerializable
Public Class ScriptBlock
Implements ISerializable
Inheritance
ScriptBlockScriptBlockScriptBlock
Implements

Remarks

 This class track a block of script in a compiled form. It is also
 used for direct invocation of the script block.

 1. Overview

 Script block comes in two forms,

 a. Full form (cmdlet form)

 This comes in following format

 {
     begin
     {
         statementlist;
     }
     process
     {
         statementlist;
     }
     end
     {
         statementlist;
     }
 }

 This form is used for running the script in a pipeline like
 a cmdlet.

 b. Simple form

 This comes in following format

 {
     statementlist;
 }

 2. Script block execution

 For the full form (or cmdlet form) of script block, the script
 block itself is part of a pipeline. Its execution is handled through
 ScriptCommandProcessor, which involves execution of begin/process/end
 blocks like a cmdlet. If a scriptblock in simple form is used in
 a pipeline, its execution is done through ScriptCommandProcessor
 also, with some of begin/process/end blocks default to be empty.

 A script block in simple form can be directly invoked (outside
 of a pipeline context). For example,

     {"text"}.Invoke()

 A scriptblock can be directly invoked internally or externally through
 runspace API.

 This class will handle the logic for direct invocation of script blocks.

Constructors

ScriptBlock(SerializationInfo, StreamingContext) ScriptBlock(SerializationInfo, StreamingContext) ScriptBlock(SerializationInfo, StreamingContext)

Protected constructor to support ISerializable.

Properties

Ast Ast Ast

Returns the AST corresponding to the script block.

Attributes Attributes Attributes

Return all attributes on a script block.

DebuggerHidden DebuggerHidden DebuggerHidden

DebuggerHidden

File File File

The script file that defined this script block...

Id Id Id

The unique ID of this script block.

IsConfiguration IsConfiguration IsConfiguration

Get/set whether this scriptblock is a Configuration.

IsFilter IsFilter IsFilter

Get/set whether this scriptblock is a filter.

Module Module Module

Get the PSModuleInfo object for the module that defined this scriptblock.

StartPosition StartPosition StartPosition

Return the PSToken object for this function definition...

Methods

CheckRestrictedLanguage(IEnumerable<String>, IEnumerable<String>, Boolean) CheckRestrictedLanguage(IEnumerable<String>, IEnumerable<String>, Boolean) CheckRestrictedLanguage(IEnumerable<String>, IEnumerable<String>, Boolean)

Check the script block to see if it uses any language constructs not allowed in restricted language mode.

Create(String) Create(String) Create(String)

Create a script block based on a script to be parsed when execution context is provided.

GetNewClosure() GetNewClosure() GetNewClosure()

Returns a new scriptblock bound to a module. Any local variables in the callers context will be copied into the module.

GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Support for ISerializable.

GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Object[]) GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Object[]) 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[]) GetPowerShell(Dictionary<String,Object>, Object[]) 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[]) GetPowerShell(Dictionary<String,Object>, Dictionary<String,Object>, Boolean, Object[]) 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[]) GetPowerShell(Object[]) GetPowerShell(Object[])

Returns PowerShell object representing the pipeline contained in this ScriptBlock

GetPowerShell(Boolean, Object[]) GetPowerShell(Boolean, Object[]) 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.

GetSteppablePipeline() GetSteppablePipeline() GetSteppablePipeline()

Get a steppable pipeline object.

GetSteppablePipeline(CommandOrigin) GetSteppablePipeline(CommandOrigin) GetSteppablePipeline(CommandOrigin)

Get a steppable pipeline object.

GetSteppablePipeline(CommandOrigin, Object[]) GetSteppablePipeline(CommandOrigin, Object[]) GetSteppablePipeline(CommandOrigin, Object[])

Get a steppable pipeline object.

Invoke(Object[]) Invoke(Object[]) Invoke(Object[])

Execute this node with the specified arguments. The arguments show up in the script as $args with $_ being the first argument.

InvokeReturnAsIs(Object[]) InvokeReturnAsIs(Object[]) InvokeReturnAsIs(Object[])

Execute this node with the specified arguments. The arguments show up in the script as $args. This overload return the raw (unwrapped) result so it can be more efficient.

InvokeWithContext(Dictionary<String,ScriptBlock>, List<PSVariable>, Object[]) InvokeWithContext(Dictionary<String,ScriptBlock>, List<PSVariable>, Object[]) InvokeWithContext(Dictionary<String,ScriptBlock>, List<PSVariable>, Object[])

A method that allows a scriptblock to be invoked with additional context in the form of a set of local functions and variables to be defined in the scriptblock's scope. The list of variables may include the special variables $input, $_ and $this.

InvokeWithContext(IDictionary, List<PSVariable>, Object[]) InvokeWithContext(IDictionary, List<PSVariable>, Object[]) InvokeWithContext(IDictionary, List<PSVariable>, Object[])

A method that allows a scriptblock to be invoked with additional context in the form of a set of local functions and variables to be defined in the scriptblock's scope. The list of variables may include the special variables $input, $_ and $this.

This overload of the function takes a hashtable and converts it to the required dictionary which makes the API easier to use from within a PowerShell script.

ToString() ToString() ToString()

Returns the text of the script block. The return value might not match the original text exactly.

Applies to