A few days ago I posted a quick PowerShell puzzle as part of an appearance announcement. Using the about_Splatting help file, what word is used the most frequently? If you can show the top 5 even better. Ideally, your code will treat words like “for,” and “for” as the same. For extra points, create a…
Tag: Pipeline
Active Directory Objects and the PowerShell Pipeline
This article is something I’ve been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn’t always the case. This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her, you probably have written a…
Why Doesn’t My Pipeline Work?
I saw a little discussion thread on Twitter this morning which I felt needed a little more room to explain. Plus since we’re in ScriptingGames season beginners might like a few pointers. I always talk about PowerShell, objects and the pipeline. But sometimes what looks like a pipelined expression in the PowerShell ISE doesn’t behave…
Rename Hashtable Key Revised
Last week I posted an advanced PowerShell function to rename a hashtable key. As usual, the more I worked with it the more I realized it was missing something – namely the ability the take a pipelined object. My original version assumed you had saved the hashtable to a variable. But as I was working…
Pipeline Power
Last week I came across a blog post that had a decent example using PowerShell and PowerCLI to get the disk location for all virtual machines. The posted code works and does display the information you might be after. $myVMs = get-vm foreach($vm in $myVMs){ $myDisks = @($vm | get-harddisk) foreach ($disk in $myDisks) {…
Have Your Output and Variable Too
There’s a relatively useful suggestion floating around on Twitter on how to save results of PowerShell command to a variable and see the results at the same time. PS C:\> ($data=get-process) I’ll admit this is a clever technique: you get the results from Get-Process written to the pipeline AND a variable $data. The other way,…
Friday Fun – Get Ranked Object
Earlier this week on Google Plus, Hal Rottenberg posted a PowerShell idea he had. His goal was to identify a group of objects that would be statistically significant. For example, given a collection of files, group the files by size but ranked by size so that you might have a group for the largest files,…
Finding Files in the Path – A Pipeline Perk
I’ve been chipping in on a forum post about finding if a given file exists in any folder within the system environmental %PATH% variable using Windows PowerShell. There are several ways you might approach this. But the best way in my opinion is to leverage the PowerShell pipeline. Perhaps you don’t really need the solution…
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….
Potential Pipeline Pitfall
Last week I was helping someone out in the PowerShell forum at ScriptingAnswers.com. The specific problem is irrelevant;l however I learned something in the process that will affect how I write my own PowerShell functions from now on. Not being a developer I never picked up on this subtle (at least to me) distinction. Here’s…
GUI vs CLI
I often talk about using PowerShell GUIs vs the console experience. There is certainly a place for a GUI, but sometimes you need the raw power that comes with a console session. Here’s an example.
Out-Notepad
Maybe this isn’t the most earth shattering PowerShell function you’ll ever come across, but it saves me a few keystrokes. There are times when I want to see the results of PowerShell expression but the console output is insufficient. I want to see the results in a text file opened in Notepad so I can easily scroll, search or whatever.