Parameter ValueFromPipelineByPropertyName Arguement

A customer pointed out that ValueFromPipelineByPropertyName wasn’t working as expected in one of their scripts. I wrote a very simple code sample to demonstrate what the syntax should look like and to show the functionality in action. Hang on, I’m getting ahead of myself… Param ([parameter(ValueFromPipelineByPropertyName=$true)] [String[]]$MachineName) The Param() statement let’s us define parameters for…

0

Parameter HelpMessage Arguement

I taught a PowerShell course the other day. I hadn’t delivered that content for a while. I came to a section and I couldn’t remember exactly how to access the configured functionality. One of those moments! After, I thought the experience would make for an interesting little post and here we are… Look at this: [CmdletBinding()] Param ([parameter(mandatory, HelpMessage=”Enter…

1

Back to Basics: Is my Parameter Value from the Pipeline?

I was asked how to check if a supplied parameter value has come from the pipeline. I came up with two different methods, the first only works with v2. Here are the two test conditions: Test-ParamSource -MyParam $vals $vals | Test-ParamSource   Where $vals is an array of integers: $vals = 3,4,5,6,40,50   Right, we…

0

Scripting Tips and Tricks: Param()

Param() – the next instalment in the exciting Scripting Tips and Tricks series! I'm a tidy person: tidy desk, tidy mind, and all that jazz. I believe in being as thorough and proper in my scripts and functions as possible. To that end, I delight in using PowerShell features such as: #Requires… to ensure certain conditions…

1

Scripting Tips and Tricks: Write-Verbose

A couple of weeks ago I reminisced about message boxes. In that post I mentioned that I use the Write-Verbose cmdlet in scripts. Here's how why and how… Why? Information sent to the verbose message stream can aid troubleshooting. It's also great for tracking the progress of a script or function. How? With version 2 of PowerShell 'advanced functions' made…

3