Monday, June 30, 2008

Do you know your aliases?


This little PowerShell script you can check how familiar you are with all the built-in aliases in PowerShell V2 CTP2.
For each alias there are 7 cmdlet names to choose from. There are 10 questions, and at the end of the quiz you can review your results and optionally run the quiz again.

You need to have PowerShell V2 CTP2 installed for the script to run.

Good luck :)



Thursday, June 26, 2008

ActiveXPoSH - PowerShell for VBScript/JScript


SAPIEN Technologies has released a new COM component named ActiveXPoSH (included in PrimalScript 2007 script editor). It is a special PowerShell host that allow developers/scripters to run single cmdlets or entire scripts from VBScript/JScript code. The component is free for personal and commercial use.

You can find more details in this document and download it from here.

Saturday, June 21, 2008

Generating TinyURLs from PowerShell


TinyURL is a web service that provides short aliases for long URLs. Here's a function to generate URL aliases using TinyURL's API. The returned URL is short and never expires.

function New-TinyUrl($url){
    (new-object net.webclient).downloadString("$url") 
PS > $vug = New-TinyUrl -url
PS > $vug
PS >


Test it in your default browser:

PS > (new-object -com shell.application).open($vug) 



Friday, June 20, 2008

Windows PowerShell Virtual User Group #6


Marco's Windows PowerShell Virtual User Group #6 is going to take place next week:
Tuesday, Jun 24 7:30pm – 10:30pm (Timezone: Eastern Time)



8:00PM-8:10PM: Introduction
8:10PM-8:40PM: Bruce Payette (Microsoft)
8:40PM-9:10PM: Wassim Fayed (Microsoft)
9:10PM-9:40PM: Hal Rottenberg
9.40PM-9:50PM: Closing


Speaker topics

Bruce Payette : PowerShell v2 modules.
Wassim Fayed : PowerShell v2 remoting.
Hal Rottenberg: Managing VMware Infrastructure using PowerShell.


To join for video:

To join for audio:
Toll free: +1 (866) 553-8146
Participant code: 5592528585


Required login information (via LiveMeeting)

Meeting ID: 5H2F88
Entry Code: 8^-\zqX


Mark your calendar :)

Wednesday, June 18, 2008

Portable PowerShell


Hallelujah! Get all the details on Karl Prosser [MVP] blog.

Tuesday, June 17, 2008

Webcast: Managing Hyper-V Virtual Machines with WMI and Windows PowerShell


Start Date: Wednesday, July 02, 2008 8:00 AM Pacific Time (US & Canada)


Event Overview

Before the beta release of Microsoft System Center Virtual Machine Manager 2008, there was only one option for automating management of Hyper-V virtual machines—Windows Management Instrumentation (WMI). In this webcast, you learn how to automate the most common management tasks, how to create a delegation model using Windows Authorization Manager, and where the power of WMI can pick up where Virtual Machine Manager leaves off. In addition, the Hewlett-Packard Windows Server 2008 Academy team shares their experience automating the deployment of 600 virtual machines in less than three hours using WMI and Windows PowerShell.

Presenters: Dung Hoang Khac, Principal Consultant, HP, and Aric Bernard, Senior Technology Consultant, HP


Register for the event.

Listing enumeration type values (updated)


The old function return duplicate names when the enumeration has two names with the same value, for example: 


PS >  Get-EnumValues Microsoft.PowerShell.ExecutionPolicy

        Name Value
        ---- -----
Unrestricted     0
RemoteSigned     1
   AllSigned     2
  Restricted     3
  Restricted     3


Here is the modified version of the function:

function Get-EnumValues([type]$type){ 
   [enum]::getNames($type) | select @{n="Name";e={$_}},@{n="Value";e={$type::$_.value__}} | ft -auto


And the results:

PS >  Get-EnumValues Microsoft.PowerShell.ExecutionPolicy

Name         Value
----         -----
Unrestricted     0
RemoteSigned     1
AllSigned        2
Restricted       3
Default          3

Monday, June 16, 2008

Scripting Sysadmin meme


In response to Steve's Scripting/Sysadmin Meme


How old were you when you started programming?

I was 27 when I started to write HTML/ASP pages.


What was your first machine?

My first real computer was Windows 95 PC. When I was 12 (I think), my uncle gave me a Texas Instruments (I can't remember the model name) but at that time I wasn't a computer geek.


What was the first real script you wrote?

Looping through ADO recordset and populating Active Server Pages (ASP).


What scripting languages have you used?

JavaScript/DHTML, VBScript/JScript.
Now that PowerShell is out all other scripting languages are set aside.


What was your first professional sysadmin gig?

I started as a sysadmin in a government institution back in 1998 and I'm still holding that position (aside from one year in which I left and returned).


If you knew then what you know now, would have started in IT?

Yes. Ever since I have been in the field I have found that being in IT brings out the best in  me.


If there is one thing you learned along the way that you would tell new sysadmins, what would it be?

Learn to script! Knowing to script is your sysadmin added value, sorts of a 'super sysadmin' if you will. You'll be able to do magic when your boss wants something that the GUI can't provide.


What’s the most fun you’ve ever had scripting?

Every day that passes with Windows PowerShell scripting is a great deal of fun. I learn something new every day.


Who am I calling out?

Alexandair Nicolic, Rolf Masuch and Andy Schneider

Sunday, June 15, 2008

PowerShell Popcorn


My son heard all the alien beeps and asked me for this one, the Popcorn tune. I couldn't say no :)


1..2  | % {
    1..2 | % {900,800,900,700,550,700,450 | % { [console]::beep($_,50); sleep -m 150}; sleep -m 250}
    900,1000,1050,1000,1050,1000,1050,900,1000,900,1000,800,900,800,900 | % { [console]::beep($_,50); sleep -m 150}
    sleep -m 250
    1..2 | % {900,800,900,700,550,700,450 | % { [console]::beep($_,50); sleep -m 150}; sleep -m 250}
    900,1000,1050,1000,1050,1000,1050,900,1000,900,1000,800,900,1000,1050 | % { [console]::beep($_,50); sleep -m 150}
    sleep -m 250    

    1..2 | % {
        1..2 | % {1350,1250,1350,1050,800,1050,680 | % { [console]::beep($_,50); sleep -m 150}; sleep -m 250}
        1350,1500,1600,1500,1600,1500,1600,1350,1500,1350,1500,1200,1350,1200,1350 | % { [console]::beep($_,50); sleep -m 150}
        sleep -m 250

Saturday, June 14, 2008

Webcast - Using Windows PowerShell with Visual Studio 2008


Event Overview

Windows PowerShell is arguably one of the coolest things to happen to developers and administrators alike. Harness the power of the Microsoft .NET Framework from the command line and learn how to write scripts in no time at all. With Windows PowerShell, we leverage your current .NET Framework experience to turn you into one heck of a good scripter.

Presenter: Zain Naboulsi, Developer Evangelist, Microsoft Corporation

The webcast is available for offline viewing.

Friday, June 13, 2008

Enhanced CSV file handling in CTP2


In PowerShell v1 you could import comma separated CSV files only. That's not a problem anymore in CTP2. The Import/Export CSV cmdlets got enhanced and now they support a new -delimiter parameter:


PS > get-help import-csv -Parameter delimiter

-Delimiter [<char>]
    Specifies the delimiter that separates the property values in the file that is being imported. The default is a com
    ma (,). Enter a character, such as a semicolon (;).

    Required?                    false
    Position?                    2
    Default value                ,
    Accept pipeline input?       false
    Accept wildcard characters?  false


Note that the delimiter is limited to a single character.

# Export processes to a space separated csv file
PS > get-process | export-csv -delimiter " " -path processes.csv
# Convert csv files: comma separated to tab separated

PS > import-csv test.csv | export-csv -del "`t" -p test1.csv

Wednesday, June 11, 2008

Close Encounters of the PowerShell Kind


Five tones:

$notes = 900,1000,800,400,600
$duration = 400,400,400,400,1600
0..($notes.length-1) | % {[console]::beep($notes[$_],$duration[$_]) }


Spaceship Siren:

1..10 | % { 370..470 | % { [console]::beep($_,5) }}


Talking alien :)

900,500,1000,800,400,600,1200,300,200,500,1100,300 | %{[console]::beep($_,100)}


CTP2 Alien:

1..20 | foreach { 
    $rnd = (Get-Random -min 0 -max 20)*100
    if($rnd -eq 0) {
        sleep -m 10
    } else {

CTP2 - Get Process/Service from remote computers


One major change to the Get-Process/Get-Service cmdlets in CTP2 is the ability to get objects from remote computers via a new parameter, computerName (or -c for short). You can map process/service objects to their computer by the machineName member.


PS > Get-Service s* -c computer1,computer2 | select name,machineName

Name                  MachineName
----                  -----------
sacsvr                computer2
SamSs                 computer1
SCardSvr              computer1
Schedule              computer1
seclogon              computer1
SENS                  computer1
ServeRAIDManagerAgent computer2

PS > Get-Process s* -c computer1,computer2 | select name,machineName

Name          MachineName
----          -----------
searchindexer computer1
services      computer2
services      computer1
slp_srvreg    computer2
smax4pnp      computer1
smss          computer2
smss          computer1
snmp          computer2
spoolsv       computer2
spoolsv       computer1

Sunday, June 1, 2008

Free eBook - TCP/IP Fundamentals for Microsoft Windows


The eBook (4.7 MB PDF), from Microsoft, describes the fundamentals of TCP/IP in Windows Vista, Windows Server 2008, Windows XP, and Windows Server 2003.