I came across a post the other day that explained differences when using the ForEach enumerator and the ForEach-Object cmdlet. They both essentially do the same thing but as the post mentions there are potential performance differences. One other difference I want to highlight is that the ForEach enumerator doesn’t write to the pipeline at…
Category: PowerShell
Ping IP Range
Last week I came across a post on using PowerShell, or more specifically a .NET Framework class, to ping a range of computers in an IP subnet. The original post by Thomas Maurer is here. I added a comment. And after looking at this again I decided to take the ball and run with it…
Export Registry Printer Information I came…
Export Registry Printer Information I came across this post http://www.oncallpros.com/2011/11/02/powershell-export-your-print-configuration-from-registry/ on exporting printer information from the registry in PowerShell. I wanted to offer some constructive suggestions but could find no way to comment so I'll do so here. First, the article introduces some good PowerShell concepts. I like that he is using Test-Path. Although I'd…
My video interview with PowerShell Magazine…
My video interview with PowerShell Magazine about the state and future of PowerShell. Recorded during the PowerShell Deep Dive in Frankfurt. http://www.powershellmagazine.com/2011/11/02/an-interview-with-powershell-expert-jeff-hicks/
Simple Where Filters
The comment about how awkward it is in PowerShell to filter out folders with Get-ChidlItem, or its alias dir, came up the other day on Twitter. I’ll be the first to admit that running a DIR command and wanting to skip folders, or perhaps you only want top level folders, is more cumbersome than we…
Convert Text to Object
Today I have another tool in my new battle regarding turning command line tools into PowerShell tools. The bottom line is we want to have objects written to the pipeline. At the PowerShell Deep Dive in Frankfurt there was a suggestion about providing tools to help with the transformation from CLI to PowerShell and this…
Friday Fun Convert Object to Hash Table
I’ve been working on a few PowerShell projects recently and one requirement I had was to turn an object into a hash table. I thought this was something that was already handled in PowerShell but I couldn’t find a cmdlet or an easy .NET technique. So I wrote my own function, ConvertTo-Hashtable. The function is…
Filter Left
When writing WMI queries expressions in Windows PowerShell, it is recommended to use WMI filtering, as opposed to getting objects and then filtering with Where-Object. I see expressions like this quite often: [cc lang=”PowerShell”] get-wmiobject win32_process -computer $c | where {$_.name -eq “notepad.exe”} [/cc] In this situation, ALL process objects are retrieved and THEN filtered….
Compress Files By Extension
I never seem to build my test virtual machines with enough disk space. Which means at some point I start dealing with space issues and resort to all sorts of hacks to buy myself a little time. One thing I do is look for files that I can compact using NTFS compression. For examples text…
Friday Fun What a CHAR!
Last week I posted a PowerShell snippet on Twitter. My original post piped an array of integers as [CHAR] type using an OFS. Don’t worry about that. As many people reminded me, it is much easier to use the -Join operator. -join [char[]](116,103,105,102) I’ll let you try that on your own. The [CHAR] type is…
The PowerShell Day Care: Building ScriptBlocks
Good morning kids and welcome to the PowerShell Day Care center. We offer a creative and nurturing environment for PowerShell professionals of all ages. Later there might even be juice and cookies. But first let’s get out our blocks, our scriptblocks, and start building. I’ve written a number of posts on script blocks and today…
Create a Read-Only PowerShell Session
In my PowerShell training class this week, I was demonstrating how to take advantage of the -Whatif and -Confirm parameters. These parameters exist (or should) for any cmdlet that changes the environment such as stopping a service, killing a process or copying a file. PS C:\> get-process | kill -whatif What if: Performing operation “Stop-Process”…
Get Process Owner
I’ve been working on my second training course for Train Signal on managing Windows Server 2008 with Windows PowerShell, specifically the lesson on managing processes. I thought I’d share a little tidbit I worked out. In fact, I hope you’ll stay tuned for other little goodies over the next several weeks. The training video will…
Filtering Empty Values in PowerShell
I saw this tip today and wanted to leave a comment but couldn’t see how. So I thought I’d post my comments here. This is actually a question I see often and there are better ways to write this kind of code. The posted tip used an example where you wanted to find processes where…
ByValue, I Think He’s Got It
Recently I responded to an email from a student seeking clarification about the difference between ByValue and ByProperty when it comes to parameter binding. This is what makes pipelined expressions work in Windows PowerShell. When you look at cmdlet help, you’ll see that some parameters accept pipeline binding, which is what you are looking for….