PowerShell Team

Automating the world one-liner at a time…

Latest posts

Jan 23, 2007
Post comments count 0
Post likes count 0

Array Literals In PowerShell

PowerShell Team

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        # array of three elements. $a = (1,2),(3,4)  # array of two elements, each of which is a two element array $a += ,(5,6)      # add another element which is an array of two element.  Now let's display the array we've built. Simply displaying the variable isn't very helpful since PowerSh...

Jan 23, 2007
Post comments count 0
Post likes count 0

How to create enum in PowerShell?

PowerShell Team

[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 enum type and use it in powershell. PS> cat enum.ps1 function New-Enum ([string] $name) {     $appdomain = [System.Threading.Thread]::GetDomain()     $assembly = new-object System.Reflection.AssemblyName     $assembly.Name = "Em...

Jan 23, 2007
Post comments count 0
Post likes count 0

Channel 9 Chat with Scott Hanselman

PowerShell Team

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 you haven't joined the Scott Hanselman fan club yet, you are missing out. Scott has a great blog at: http://www.hanselman.com/blog/default.aspx and is a frequent speaker at conferences. He as a cool way of demo'ing PowerShell so even if you know PowerShell, you'll get a ...

Jan 17, 2007
Post comments count 0
Post likes count 0

IPCONFIG/All

PowerShell Team

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, operable program, or script file. Verify the term and try again.At line:1 char:12+ ipconfig/all <<<<PS> In PowerShell, you have to put a space to separate the command name and the parameter (.e.g. ipconfig /all ) I know that and yet time and time again, I type it i...

Jan 17, 2007
Post comments count 0
Post likes count 0

PowerShell Analyzer: The Video

PowerShell Team

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 as to how many features he has put into PowerShell Analyzer. I found the Pause button to be my friend while watching this. J He also has posted a series of screenshots on the website so that really helps. In the end, you can always just download it and start using it. Y...

Jan 16, 2007
Post comments count 0
Post likes count 0

Custom Alias Listing

PowerShell Team

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) (PowerShell -NoProfile {Get-Alias}) -Property Name |sort SideIndicator,NameName SideIndicator---- -------------?: <=?? <=?s ...

Jan 16, 2007
Post comments count 0
Post likes count 0

Managing Processes in PowerShell

PowerShell Team

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:   but in shells ( PowerShell, cmd.exe, bash, etc.) you can simply start a program like notepad simply by typing "notepad" as shown.   Now you'll notice that when you do this the shell returns immediately and prompts for the next command. This is b...

Jan 12, 2007
Post comments count 0
Post likes count 0

Difficulties Reading Our Blog

PowerShell Team

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 the post starts right after that without an extra linebrake to seperate the content from the styling. KJARTAN  - THANKS FOR SPEAKING UP!  I didn't realize that this was a problem.  I'll look into what I can do to fix this or switch formating.  I moved to...

Jan 11, 2007
Post comments count 0
Post likes count 0

Set-Alias-Strict

PowerShell Team

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, $Value){    $null = Get-Command $Value    Set-Alias $Name $Value    } Set-Alias sals Set-Alias-Strict Here is that function in action: PS> Set-Alias        test Get-PorcessPS> Set-Alias-Strict...