Welcome to MSDN Blogs Sign in | Join | Help

Browse by Tags

All Tags » ScriptBlock   (RSS)

Get closure with GetNewClosure

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,

Tied Variables in PowerShell

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 ()
Posted by PowerShellTeam | 4 Comments
Filed under: , ,

Attachment(s): New-ScriptVariable.ps1.txt

Creating arbitrary delegates from scriptblocks in PowerShell...

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
Posted by PowerShellTeam | 18 Comments
Filed under: ,

Attachment(s): get-delegate.ps1

Casting a scriptblock to an arbitrary delegate signature

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
Posted by PowerShellTeam | 4 Comments
Attachment(s): h.ps1
 
Page view tracker