PowerShell Team
Automating the world one-liner at a time…
Latest posts
Year of the Pig Revisited – the magic of QL
Richard Siddaway has a blog entry showing how to calculate the Chinese Horoscope using PowerShell. His solution uses hashtables: ## create hash table $years = @{1="Rat"; 2="Ox"; 3="Tiger"; 4="Rabbit"; 5="Dragon"; 6="Snake"; 7="Horse"; 8="Goat"; 9="Monkey"; 10="Rooster"; 11="Dog"; 0="Pig"} ## get the year of interest $y = Read-Host "Enter a year between 1900 and 2100 inclusive" $anml = ($y - 1899)%12 Write-Host $years[$anml] This is a perfectly fine solution and a good one to help get hashtables in focus. Hashtables are super useful in scripting so if you aren't real co...
Pause
In the Newsgroup Microsoft.Public.Windows.PowerShell, BJ Stigall asked what the equivalent of the batch file PAUSE function was in PowerShell. There were lots of good answers that came close but I think the one below comes the closest (and a little bit better). function Pause ($Message="Press any key to continue..."){Write-Host -NoNewLine $Message$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")Write-Host ""} Here is an example of it in use: PS> pausePress any key to continue...PS> pause "Press any key to win a million dollars..."Press any key to win a million dollars...PS> Of course you can see...
Supporting -Whatif, -Confirm, -Verbose – In SCRIPTS!
<This is a super-important issue so you should definitely start using this in your scripts that you share with others (that have side effects on the system). Please try it out and blog about it to others so that it becomes a community norm. Thanks-jps> One of the greatest things about PowerShell is that when you use a Cmdlet which is going to have a side effect on the system, you can always type –Whatif, -Confirm or –Verbose. Sadly, you lose this option when it comes to scripts. Over time we want to makes scripts be the semantic equivalent of Cmdlets – that is to say that a Cmdlet is a Cmdlet independent o...
NetBeans IDE support for PowerShell
Apparently one of the main themes of NetBeans 6.0 is going to be support for scripting languages (yet another indication of the industry wide ascendency of Scripting. It is a VERY good time to embrace scripting or "learn PowerShell and increase your integrated lifetime earnings" J). HERE is a blog entry of someone that added PowerShell support to NetBeans. Good stuff! It is awesome to see all the IDEs that now support PowerShell. I look forward to the day when I can tell you that if you want a great PowerShell IDE you can use Visual Studio. J Jeffrey Snover [MSFT]Windows PowerShell/MMC ArchitectVisit the Wi...
Displaying USB Devices using WMI
Over on MyItForum.com, I came upon a VBScript in a forum to find all the PNP entities associated with a USBController. I rewrote it in PowerShell and was pretty happy with the results so I thought I would share them. The first thing you need to understand is that the WMI class WIN32_USBControllerDevice describes the connection between USB controllers (The Antecedent) and their logical devices [CIM_LOGICALDEVICE] (the Dependent). Let me illustrate: PS> gwmi Win32_USBControllerDevice |fl Antecedent,DependentAntecedent : \\JPSVISTA1\root\cimv2:Win32_USBController.DeviceID="PCI\\VEN_ 8086&DEV_2...
Extended Types and Types.XSD
I'd like to draw your attention to a really important blog entry that Jim Truher recently made: PowerShell Extended Types (Includes a TYPES.XSD). In that entry, he talks about how powerful PowerShell's extended type system is. He is absolutely correct on this point, this is an incredibly important and powerful feature of the system that not enough people know about or are using. The basic idea is that you can have a set of XML files which add additional properties and methods to existing types. The great thing that Jim did was to take the type to create an XSD for the XML files (I know- I know – it is our bad ...
Time till we land …
<Today we have a guest blog entry from Ed Wilson – Author of the upcoming MSPRESS book, Microsoft Windows PowerShell Step By Step> <2/16 fixed a bug pointed out by Richard Siddaway [use TotalMinutes instead of Minutes for the out-gauge]. Thanks Richard! -jps> I was on my way to Ottawa this week, and working on a few scripts, when I realized that perhaps I might need to keep track of time. My poor old combination laptop/coffee warmer is struggling to keep up the pace, and as a result I need a good five minute warning to shut the silly thing down prior to landing. The flight attendants do not us...
Why isn’t “New-Object” aliased to “New”
Alistair Young made a Note to Self : In a standard PowerShell installation, "new" is not an alias for "new-object". You added that. You should therefore know better that to make this kind of dumbass mistake. We talked about making "New" an alias to "New-Object" but decided against it in the end because it leaves open the door for us to provide a C#-like NEW keyword sometime in the future. We want PowerShell to provide a nice glide path to C# so in the future, we'd like the following to be equivalent: $x = New-Object System.DateTime 2007,12,25 $x = new System.DateTime(2007,12,25) So if we decide to implement this...
Admin Development Model in Action
Ken Taylor has a PowerShell blog over on LiveSpaces. Today he posted a blog entry, Enabling RDP with PowerShell, that had me jumping for joy as a perfect example of the Admin Development Model in action. The whole point of the admin development model is that you use tools to quickly investigate the system and manage it. Ken needed to enable RDP on a remote Server and remembered that it was possible to do via WMI. Read his blog for the steps he used to quickly and easily investigate the system to find exactly want he needed to do within 2 minutes!. The only thing Ken didn't do was to encode this information i...