PowerShell Team
Automating the world one-liner at a time…
Latest posts
Accessing data past the end of an array
In the newsgroup Microsoft.Public.Windows.PowerShell Marco Shaw asked about accessing data past the end of a defined array. He wondered why he didn't get an error. As a general rule in PowerShell, when you ask for something that doesn't exist, you get an NULL not an error. PS> $array=@(0,1,2)PS> if ($array[1] -ge $array[50000]) {"ge"}gePS> if ($array[1] -ge $NoSuchVariable) {"ge"}gePS> The exception to this rule is when you enable STRICT mode. STRICT mode is limited in V1, it throws an exception when you access a variable that does not exist. B...
Sorting out -GroupBy
Did you realize that Format-Table had a parameter -GroupBy? This tells Format-Table to generate a series of tables instead of a single table. The best way to get this in focus is to show an example. For the purposes of this blog entry, I'm going to use the aliases GSV for Get-Service and FT for Format-Table. Also, I don't want too much data for the examples so I'm going to leverage the fact that GSV supports wildcards and specify s[p-z]* which says give me all the services that start with "s" and whose second character is between "p" and "z" inclusive. There is nothing sp...
Behind PowerShell Installer (for Windows XP / Windows Server 2003):
The information here relates to Windows PowerShell 1.0 installer on downlevel platforms (XP SP2, W2K3 SP1 and above). The job of installers is to create an environment on a user’s machine, so that the underlying software works seamlessly on the machine. Typically most installation scripts copies some files and sets some registry keys. This appears to be simple on the first hand but it gets little complicated if you bring servicing into picture. Installation script must ensure that the underlying software is serviceable. Herein I will try to explain what Windows PowerShell installer does behind the scenes. Instal...
2 + 2 equals "Monday Evening"
I wanted to follow up on Jeffrey's post and one of the comments. It has to do with this example: The reason that we get a double rather than an int is because of precedence. The conversion has a higher precedence than the division operation, so what really means is: "Convert 1 to an integer and then divide by 2", which will result in a double (0.5). If we really want our results to be an integer, we should do the following: which first does the division and then converts to an integer. Viola, we get what we want! Jim Truher [MSFT]Windows PowerShell Program ManagerVisit the Windows Power...
Two plus two equals "Monday" ?
In PowerShell, two plus two does not always equal four. Why? Because there are twos and there are twos. Let me explain. PowerShell does a ton of work on your behalf so you can think about what you want to do and not how to do it. Think about the difference between an automatic transmission and a manual one. An automatic does a ton of work on your behalf but sometimes it doesn't have the information to make the right decision. That is why automatic transmissions allow you to shift into 1, 2 ,3 or D (which automatically shifts for you). Occassionally, y...
Windows PowerShell for Testers
The PowerShell team is very much into unit testing so, when I ran into this blog by Adam Geras today, I found it very interesting. All its entries are on using PowerShell for testing. I especially liked this entry on using PowerShell and Excel for data driven testing because I always love it when you can leverage other products to make your life easier. I find Excel to be great for manipulating lots of data. Being able to keep your data in a spreadsheet and still have access it from PowerShell is awesome. It seems Adam is also working on a CodePlex proje...
"PowerShell … is there anything it CAN'T do?"
This weekend my wife was searching for some stuff and came across the following photo on Flickr : http://www.flickr.com/photos/windbag/167080724/ Apparently someone had taken a photo of the one of the slides during my TechEd talk. I just loved the comment. This one has a fun comment as well: http://www.flickr.com/photos/windbag/167080753/ Jeffrey Snover [MSFT]Windows PowerShell/Aspen ArchitectVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.m...
Yet Another Freakishly PowerFul PowerShell One-liner
MOW has done it again. Check out http://thepowershellguy.com/blogs/posh/archive/2007/01/06/it-is-to-me.aspx for another one of MOW's freakishly powerful PowerShell one-liners. It is so powerful and pithy that makes my head spin. Enjoy! Jeffrey Snover [MSFT]Windows PowerShell/MMC ArchitectVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
Cliff Notes of ConvertTo-Html & Other Language Blogs
I just saw a PowerShell blog entry on spaces ( http://hung-yuwu.spaces.live.com/Blog/cns!744FB258BF8C8020!1291.entry ) but it was in a language I don't read (I think it was Japanese)*. I thought I would check it out for yucks and was delighted to realizes that while I couldn't understand anything the blogger was saying, I could perfectly understand the scripts. This blogger provided a great Cliff notes version of ConvertTo-Html , starting out simple, and then step-by-step, adding a concept and seeing what it does. It starts off showing the results of Get-Services in html. Then it picks jus...