Open PowerShell Cookbook Beta Available Online

With the first draft of the Windows PowerShell Cookbook complete, we’re running an open beta through a cutting-edge platform called the Open Feedback Publishing System: http://powershell.labs.oreilly.com. In this system, we put the entire book online and let you read to your heart’s content. Not only is the book available online, but you can also influence its future. The Open Feedback Publishing System lets you attach comments to any paragraph as though you would comment on a blog.

HTML Agility Pack Rocks Your Screen Scraping World

I had to do some deep data extraction from a web page today, and naturally leaned on PowerShell for some assistance. PowerShell is a great language for text munging, and web content is no different. There are tons of examples online, but here’s an example from earlier in this blog: http://www.leeholmes.com/blog/PowerShellTheOracleInstantAnswersFromYourPrompt.aspx. As I looked at the underlying HTML of this page, though, my heart sank. I cared about four pieces of data, and they were arranged without much structure on the web page.

Responding to USB Devices in PowerShell

I recently got a cool USB MIDI keyboard (M-Audio Axiom 49) and software (Propellerhead Reason) combo that lets me play keyboard with all kinds of cool sounds effects and general fun. Despite how cool the system is, it’s not quite as spontaneous as a plain ol’ electronic keyboard. Just to piddle around for a bit, you have to turn on the keyboard, launch Reason, create a new song, add a virtual instrument, and then start playing.

PowerShell Hotkey to Pause Pandora

I’ve got a neat application that I use to map keystrokes to background PowerShell functions / script blocks. I recently started using Pandora more often, and the killer problem is when somebody drops by the office to ask a quick question. You dig around all of your open Explorer windows until you find the one for Pandora, then find the Pause button. Here’s a function that does all of that for you, and maps it to Control+Alt+P:

Looking for Reviewers for PowerShell Cookbook v2

We’re getting close to “content complete” of the Windows PowerShell Cookbook, 2nd edition. The next step is technical review, where we look for both high-level and low-level feedback on the content and structure. Also, this is a book focused on administrators. While PowerShell uber-hackers are always appreciated, inexperience with PowerShell is extremely valuable, as well. If you’re interested in being a Technical Reviewer of the book, participate in its Open Beta!

Delayed Screen Captures in PowerShell

Here’s one that’s short and sweet. A lot of programs exist for the sole purpose of taking a screen shot after a certain amount of time. For example, delay for 10 seconds before taking a screen shot so that you have the time to open some menus. This is incredibly simple with PowerShell: Add-Type -Assembly System.Windows.Forms Sleep 10 ## Capture the entire screen [System.Windows.Forms.Sendkeys]::SendWait("{PrtSc}") ## Capture the current window [System.Windows.Forms.Sendkeys]::SendWait("%{PrtSc}")

Where is Rename-Computer?

In PowerShell V2, we added a bunch of computer management cmdlets: PS >Get-Command -Noun Computer | Format-Table -Auto CommandType Name Definition -———- —- ———- Cmdlet Add-Computer Add-Computer [-DomainName] [-Credent Cmdlet Checkpoint-Computer Checkpoint-Computer [-Description] [ Cmdlet Remove-Computer Remove-Computer [[-Credential] Cmdlet Restart-Computer Restart-Computer [[-ComputerName] <String[]>] Cmdlet Restore-Computer Restore-Computer [-RestorePoint] [-Ve Cmdlet Stop-Computer Stop-Computer [[-ComputerName] <String[]>] [[ Astute followers of our CTP process might notice a missing entry in this list when compared to earlier builds: the Rename-Computer cmdlet.

An Exercise in De-Obfuscation

I don’t like to post line noise very often, but I did break that exception in the Holiday Wishes post a few weeks ago. I hate quoting entire blog posts, but, 177 characters isn’t too bad: '(18029799997931744,139752119745773792|%{"{0,60}"-f [Convert]::ToString($_, 2).Replace("0"," ")})-split''(.{12}|Mh)''|?{$_}'|%{iex $_;-join[char[]]$_[[char[]]"nOBB7[4oBCaenRa"]} When it runs, you get this for output: PS >'(18029799997931744,139752119745773792|%{"{0,60}"-f [Convert]::ToString ($_, 2).Replace("0"," ")})-split''(.{12}|Mh)''|?{$_}'|%{iex $_;-join[char[] ]$_[[char[]]"nOBB7[4oBCaenRa"]} 1 111 11111 1111111 111 11111 111111111 11111111111 111 111 Merrv ChristMas While it may seem like magic, it in fact was not – just some terribly obtuse PowerShell scripting.

Holiday Wishes

'(18029799997931744,139752119745773792|%{"{0,60}"-f [Convert]::ToString($_, 2).Replace("0"," ")})-split''(.{12}|Mh)''|?{$_}'| %{iex $_;-join[char[]]$_[[char[]]"nOBB7[4oBCaenRa"]}

Hex Dumper in PowerShell

Marcel has been posting some interesting articles on using PowerShell to generate the MD5 hashes of files. Now, an MD5 hash of a file is just an array of bytes. Typical hashing programs display this in a more friendly manner: PS:15 C:\Temp >md5sum 71-59-B7.bmp a05805e638741bb767f97c0e88962952 *71-59-B7.bmp Although the output of Marcel’s scripts could definitely be crafted to display this output, they currently output the string representation of a byte array: