Showing results for ScriptBlock - PowerShell Team

Mar 27, 2009
Post comments count0
Post likes count0

Get closure with GetNewClosure

PowerShell Team
PowerShell Team

Have you ever created scriptblocks on the fly, say in a foreach loop, and they totally mess up because they all have the same value? This is something sort of advanced, and typically used when you’re proxying an object. The most basic example would be, taken from (http://www.powershellcommunity.org/Forums/tabid/54/aff/1/aft/2506/afv/topic/Default.a...

CTP3Advanced FunctionsScriptBlock
Mar 26, 2009
Post comments count0
Post likes count0

Tied Variables in PowerShell

PowerShell Team
PowerShell Team

With Add-Type and $executioncontext you can add special varibles that have tied values. I made $random, and $now add-type @"using System;using System.Management.Automation;public class RandomVariable : PSVariable{Random r;public RandomVariable ()  : base("Random", 0, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope)  {r = new Rand...

CTP3Add-TypeScriptBlock
Jul 25, 2006
Post comments count0
Post likes count0

Creating arbitrary delegates from scriptblocks in PowerShell…

PowerShell Team
PowerShell Team

People have been asking about creating arbitrary delegates out of scriptblocks. As Jeffrey has mentioned, this isn't directly supported in V1.0 of PowerShell. It is, however, possible to do it using dynamic methods and the CreateDelegate call. Here's a script (also attached) that will do it. I haven't tested this very much so it may not work in all...

ScriptBlockDelegates
Jul 24, 2006
Post comments count0
Post likes count0

Casting a scriptblock to an arbitrary delegate signature

PowerShell Team
PowerShell Team

Arild asked the following in http://arildf.spaces.msn.com/blog/cns!E99F8B43533149B0!140.entry?_c%3dBlogPart : PSMDTAG:FAQ: Delegates - how to cast a scriptblock to an arbitrary delegate signature? ANSWER - You can't in V1.0. In version 1.0 Windows PowerShell only supports casting scriptblocks to delegates with the signature: vo...

FAQDOTNETScriptBlock