PowerShell Team

Automating the world one-liner at a time…

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 ()  : base("Random", 0, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope)  {r = new...

V2: Custom Enums

Once again MOW proves what a clever guy he is.  Check out his blog entry PowerShell V2 CTP2: making Custom Enums using Add-Type. He shows how you can make your own enums using a very simple function he wrote (Add-Enum) which leverages our new Add-Type cmdlet.  Wonderful stuff. Add-Type is one of those huge game-changing features that...

Show-PowerShell / Hide-PowerShell

During the Week of WPF, someone requested an example of how to minimize the PowerShell window. Here's a quick module to make it happen.  Copy/paste the code below into Documents\WindowsPowerShell\Packages\PowerShell\PowerShell.psm1 $script:showWindowAsync = Add-Type –memberDefinition @” [DllImport("user32.dll&...