PowerShell Team

Automating the world one-liner at a time…

Latest posts

Dec 18, 2006
Post comments count 0
Post likes count 0

Apologizes for delays in approving comments

PowerShell Team

We had a bad windstorm here and most people have been without power since Thursday night.  Microsoft was closed on Friday and power got restored sometime during the weekend.  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.mspx  

Dec 14, 2006
Post comments count 0
Post likes count 0

ConfirmPreference

PowerShell Team

With Windows PowerShell you can specify -CONFIRM on commands that have a side-effect on the system and it will ask you whether to perfmon the action or not.  e.g. PS> Stop-Process 7004 -Confirm ConfirmAre you sure you want to perform this action?Performing operation "Stop-Process" on Target "calc (7004)".[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): yPS> But you can also configure the system to automatically confirm operations based upon their impact on the system.  When developers write their cmdlets, they can declare the impact o...

Dec 14, 2006
Post comments count 0
Post likes count 0

KB: 1024 vs 1000

PowerShell Team

I love the fact that we designed PowerShell for Admins and IT Pros and love to demonstrate what that means.  Often I'll demo PowerShell and show how you can use "KB", "MB", and "GB" as I did in my previous blog entry: PS> 1kb1024PS> 1mb1048576PS> 1gb1073741824PS> 1kb+2mb+3gb3223323648 Almost uniformly, the crowds LOVE this but every now and a again someone make the point that "kb" should be 1000 not 1024.  One of our readers (Dan) made this point in comments to the last post and even provided a pointer to a Wikipedia article to back up his position.  This is not an unreasonable pos...

Dec 14, 2006
Post comments count 0
Post likes count 0

File Aging Script

PowerShell Team

Jeffery Hicks as a very nice File Aging script.  The thing that Iike about it is that it provides a very good illustration of how to use a number of PowerShell features including: He had one technique that could be improved.  Here is a line from the script:  $GrandTotal="{0:N2}" -f ($GrandTotal/1048576) The question is, what is that number?  Well you might guess that that is 1 MegaByte and you are probably correct but are you sure that a MegaByte isn't 1045876?  I transpose numbers all the time, maybe Jeffery did as well.  He didn't but you see the points 1) if it was wrong - ...

Dec 13, 2006
Post comments count 0
Post likes count 0

[SWITCH]

PowerShell Team

Here is a pointer to a good demonstration of PowerShell's [SWITCH] datatype: http://msgoodies.blogspot.com/2006/12/negating-powershell-switch-parameters.html 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

Dec 11, 2006
Post comments count 0
Post likes count 0

$OutputEncoding to the rescue

PowerShell Team

You might have noticed that “findstr” does not work properly with non-English text in PowerShell. For example: Let’s create a text file with some Chinese characters in it. PS C:\> ${c:\test.txt}="中文" Try to use findstr to find  one of the Chinese characters, and it did not find anything. PS C:\> Get-Content test.txt | findstr /c:中 The same command works in Cmd.exe. PS C:\> cmd /c "findstr /c:中 test.txt" 中文   What went wrong? When we pipe output data from PowerShell cmdlets into native applications, the output encoding from PowerShell cmdlets is controlled by the $OutputEncoding variable, which ...

Dec 10, 2006
Post comments count 0
Post likes count 0

Windows PowerShell SDK

PowerShell Team

Windows PowerShell Software Development Kit (SDK) is now available as part of Microsoft Windows SDK for Windows Vista. Microsoft Windows SDK can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en Windows PowerShell SDK contains: The documentation can also be found on msdn at http://msdn2.microsoft.com/en-us/library/aa830112.aspx To install Windows PowerShell components from Microsoft Windows SDK, please select the check-boxes as shown in the attached image.  Hemant Mahawar [MSFT]Program ManagerWindows PowerShell PowerShel...

Dec 8, 2006
Post comments count 0
Post likes count 0

Get-Weather

PowerShell Team

Jeffery Hicks has a very cool blog entry where he defines a Get-Weather script which downloads the weather from yahoo.com, casts the results to XML and then reports the weather using the Speech object.  It's totally cool.  I'm going to show it off today during my demo.  I'm down in LA meeting with MySpace and getting a tour of the operations and seeing how they use PowerShell to manage their production servers.  I get to do a demo at their Friday "Dojo" meeting (Pizza and presentation).  As a kid, I used to go to "old-school" Uechi-Ryu Dojo where they used to hit us while doing kat...

Dec 7, 2006
Post comments count 0
Post likes count 0

Resolve-Error

PowerShell Team

Recently I posted the following to the Microsoft.Public.Windows.PowerShell newsgroup (which you should participate in if you are not yet)  Below is a function that I encourage you to add to your Profile files and then use when reporting an error or ask a question about a exception you are seeing.  This function provides all the information we have about the error message making it easier to diagnose what is actually going on.function Resolve-Error ($ErrorRecord=$Error[0]){   $ErrorRecord | Format-List * -Force   $ErrorRecord.InvocationInfo |Format-List *   $Excep...