Hash to Arrayof Objects

As an old-time Perl user, I love hashes.  In Perl, hashes are the answer, no matter what the question is.  (No, not really, but they solve a lot of problems.)  In PowerShell, hashes are cool, but you can’t do things like “Sort-Object -property value”. Here’s a quick-and-dirty way to convert a hash into an array…


Propagating Default Options

Let’s say I have a function that takes parameters, which all well-written ones should.  And they have intelligent defaults, again as well-written ones should.  The outer script exposes those parameters via the outer param() statement, but how do I pass them into the script?    param ($foo = $null); function Test-It {    param ($foo = $(…


No Reply All

Short form: Go here http://research.microsoft.com/en-us/projects/researchdesktop/noreplyall.aspx Longer form: Outlook/Exchange, like so many other products, has some ‘undocumented features’, including a one-bit flag that allows reply-all or not.  This helpful download from Microsoft Research exposes that control.  


Heavyweight Help in V1

Again, in V1 PSH, this is what I use for nicely formatted help.  If you’re on V2, by all means, use the inline help, PLEASE! function Break-Line {    # synopsis::    # [-help]    #    # Description::    # Inserts linefeeds into strings read from STDIN so they wrap nicely    # for a given PowerShell window’s screen geometry   …


Quick and Dirty Help

I like writing help text for my scripts.  Yes, PSH V2 allows Get-Help to parse the inline help in scripts, but I’m stuck in V1 for my production environment.  For quick-and-dirty scripts where I don’t want to implement a ‘real’ help subsystem, I use the following:     if ($help) {        $functionName = (Get-Variable MyInvocation -Scope…


Getting Remote Event Logs

Here’s a quick-and dirty script to save event logs via LogParser.   function Get-RemoteEventLog {    ##    ## SYNTAX    ##      Get-RemoteEventLog [-computer <string>] [-log <string>]     ##      [-logpath <string>] [-logParserPath <string>] [-clause <string>]     ##      [-day <int>] | [-help]    ##    ## DESCRIPTION    ##      Saves Event Log from remote machine via LogParser.exe as CSV (to     ##     …