PowerShell Team

Automating the world one-liner at a time…

Latest posts

Get closure with GetNewClosure
Mar 27, 2009
Post comments count 0
Post likes count 0

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.aspx) function add([int]$x) { return { param([int]$y) return $y + $x } }$m2 = add 2$m5 = add 5&$m2 3 #expected:  5 actual: 3&$m5 6 #expected: 11 actual: 6 The value for $x is $null for both. Why is that? Its because $x is $null in the local scope, the script...

Tied Variables in PowerShell
Mar 26, 2009
Post comments count 0
Post likes count 0

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 Random();}     public override object Value        {            get            {     ...

Get-ProgID
Mar 20, 2009
Post comments count 0
Post likes count 0

Get-ProgID

PowerShell Team
PowerShell Team

The other day, a friend over in Microsoft Research wanted to figure out how to get out the width and height of an image in PowerShell.  There are many ways that you can approach this particular problem.  I knew three right off of the top of my head, but none of them had a really optimal experience. I knew there had to be a better way.  Some object had to be able to give me back image width and height as a nice simple property. I normally use two functions to find my way around unfamiliar problems (before I start using search engines).  One I’ve shared out a few times is called ...

Active Directory Powershell Blog
Mar 20, 2009
Post comments count 0
Post likes count 0

Active Directory Powershell Blog

PowerShell Team
PowerShell Team

AD team has started a new blog for their PowerShell Cmdlets.. In their own words "We are here to answer any questions about AD Powershell, share some tips and tricks, discuss the history behind certain decisions and features and hear your feedback on improving AD Powershell experience" Check this out http://blogs.msdn.com/adpowershell/  Osama Sajid

Local Boy Makes Good
Mar 16, 2009
Post comments count 0
Post likes count 0

Local Boy Makes Good

PowerShell Team
PowerShell Team

Check it out:  http://www.microsoft.com/presspass/exec/de/snover/default.mspx One of the biggest Snoopy Dance moments of my life!   BTW - this is really a reflection of how important Microsoft views PowerShell. I'd love to say more but I've got some Snoopy Dancing to do.   Experiment! Enjoy! Engage! Jeffrey Snover [MSFT] Windows Management Partner Architect Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

dir –a:d
Mar 13, 2009
Post comments count 0
Post likes count 0

dir –a:d

PowerShell Team
PowerShell Team

In cmd, listing files based on attributes was simple: In PowerShell, it’s not so easy: We have had requests to cover the first case better, for example: https://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=252549&wa=wsignin1.0 https://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=308796&wa=wsignin1.0 We haven’t added such a parameter to Get-ChildItem yet, but with some new features in V2, you can add them yourself. The techniques I describe below can be used to augment any cmdlet, or any script or function for that matter. If you don’t care much a...

Reserving keywords
Mar 11, 2009
Post comments count 0
Post likes count 0

Reserving keywords

PowerShell Team
PowerShell Team

A couple months ago we asked our MVPs how they felt about reserving keywords in V2.  We received some excellent but mixed feedback, so we’d like to open the discussion up a bit wider. There are keywords we hope to use in a future version of PowerShell, but won’t be implemented in V2.  “class”, “using”, and “new” are excellent candidates for additions to PowerShell, but we haven’t decided on the exact list yet. Because V1 did not reserve these keywords, reserving them now would be a breaking change.  For example, some people like to add an alias like: If we reserved “new”, scripts using this alias w...

Out-GridView Revisited
Mar 11, 2009
Post comments count 0
Post likes count 0

Out-GridView Revisited

PowerShell Team
PowerShell Team

It has been more than one year since we updated Out-GridView feature with you. In case you are not familiar with Out-GridView yet, it is a unique PowerShell cmdlet that users can pipe command output to a separate window, and it enables users organize and analyze output data easily. The previous blog entry by Brent gave an overview of Out-GridView cmdlet. So, what’s new for Out-GridView in Windows PowerShell CTP3? A major feature we added was query filtering functionality; data can be queried according to their properties through this feature. Let’s look at an example. Running command: “Get-ChildItem | Out-GridV...

How to Create an Object in PowerShell
Mar 10, 2009
Post comments count 0
Post likes count 0

How to Create an Object in PowerShell

PowerShell Team
PowerShell Team

Today someone in Xbox Live Operations (the folks that keep xBox Live alive and well) pinged me with a simple question about PowerShell with a complicated answer: “How do I create a class in PowerShell?” There’s two scenarios I find where people want classes.  The first (and most common) is familiarity: the person wants to make a class in PowerShell because they think of problems in terms of classes.  The second is practical: the person wants to make a collection of properties and methods, because that’s what the pipeline in PowerShell plays nicely with (for instance, you can Gro...