ScriptBlock Class

Definition

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

public class ScriptBlock : System.Runtime.Serialization.ISerializable
Inheritance
ScriptBlock
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)

Protected constructor to support ISerializable.

Properties

Ast

Returns the AST corresponding to the script block.

Attributes

Return all attributes on a script block.

DebuggerHidden
File

The script file that defined this script block...

Id
IsConfiguration
IsFilter

Get/set whether this scriptblock is a filter.

Module

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

StartPosition

Return the PSToken object for this function definition...

Methods

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 a script block based on a script to be parsed when execution context is provided.

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)

Support for ISerializable.

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

Returns PowerShell object representing the pipeline contained in this ScriptBlock

GetPowerShell(Boolean, Object[])
GetSteppablePipeline()

Get a steppable pipeline object.

GetSteppablePipeline(CommandOrigin)

Get a steppable pipeline object.

GetSteppablePipeline(CommandOrigin, 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[])

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(IDictionary, List<PSVariable>, Object[])
ToString()

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