PowerShell Team

Automating the world one-liner at a time…

Array Literals In PowerShell

The first thing to understand is that there are no array literals in PowerShell J Arrays are built using operators or casts. The way to build an array in PowerShell is to use the comma operator as shown in the following examples:  $a = , 1          # array of one element $a = 1,2          # array of two elements $a = 1,2,3...

How to create enum in PowerShell?

[Updated to comply with the naming guidelines (create=>new)] Dynamic assembly emitting techniques can be used to create new classes or data types in PowerShell. Trick is that right permission needs to be set so that data types created in dynamic assembly can be used subsequently. Following is an example for creating a new ...

Channel 9 Chat with Scott Hanselman

A while ago I had the great pleasure to interview Scott Hanselman for Channel 9.about a wide range of topics. It was a blast. Think of it as the geek equivalent of My Dinner with Andre. Ok well neither of us are as interesting as that but Scott comes close (and I did get to drop a reference to Kierkegaard which always brightens my day). If...

IPCONFIG/All

While using CMD.exe, I got into a number of bad habits. One of those is the habit of eliminating whitespace for various commands. The problem is that that causes problems with PowerShell. More precisely stated – it doesn't work. Here is what you get: PS> ipconfig/allThe term 'ipconfig/all' is not recognized as a cmdlet, function, ...

PowerShell Analyzer: The Video

If you haven't already installed PowerShell analyzer, you can now check out want it does by watching the video. Karl Prosser recently released a 7 minute video showing you a run-through (as opposed to a walk-through) of its features. Now that fact that he spends 7 minutes and has to run through the features should give you a bit of a clue ...

Custom Alias Listing

When you run Get-Alias, it shows you all the aliases currently available. You might want to know which aliases were Custom aliases. That is to say, which aliases did not come built in with PowerShell. So what does it take to answer this question? With those 4 things in focus, you can answer the question: PS> Compare-Object (Get-Alias) (...

Managing Processes in PowerShell

Several people have asked recently about how to manage processes in PowerShell. This blog post should answer a number of those questions. As one might expect from the "shell" part of PowerShell, you don't have to do special anything to start a process . In a programming language such as VBScript, you have to do something fairly complex like...

Difficulties Reading Our Blog

Kjartan posted the comment:  I really like reading your blog and have done so for a long time now, but since I mostly read blogs with the RSS-reader in IE7 the styling of the code samples makes the posts harder to read, for some reason IE7 (at least the version I'm using Vista RC1) dispays the styling as a big chunk of text and...

Set-Alias-Strict

I picked up Jerry Lee Ford's book Microsoft Windows PowerShell Programming for the absolute beginner .  In the section on aliases, he warns users that Set-Alias does not verify the validity of the alias assignment.  That is a good point.  Here is a function that does that for you.  function Set-Alias-Strict($Name, $...

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...