Scripting Tips & Tricks: Dynamic Parameters

Imagine you want a secondary parameter (or set of parameters) to ONLY appear if a particular value has been supplied to an initial parameter… Eh? Ok, so you have Parameter A. You supply Value A to Parameter A and you now, and only now, have access to Parameter B. Furthermore, if you were to supply…

0

Scripting Tips & Tricks: Dynamic RegEx Queries

Another week of RegEx! I just can’t get enough of it at the moment. A bit like sleep. I said sleep, not sheep! Man, I do like a good sleep. I’m writing this at an airport. It’s way past my bedtime. Anyway… what do I have for you this week? Well, I feel like a…

0

Scripting Tips & Tricks: RegEx for OU Name & Path

I ‘borrowed’ this RegEx off my esteemed colleague, Mr Raimund Andree, whilst working on site with him.   $pattern = ‘(..=)(?<Name>.*?)(?<!\\),(?<Path>.*)’   You can use this pattern to match the ‘Name’ of the OU and its parent ‘Path’ into named groups with those exact same names.   $a = “OU=TEST,DC=Halo,DC=net”,”OU=BATCH1,OU=TEST,DC=Halo,DC=net”,”OU=BATCH2,OU=TEST,DC=Halo,DC=net”,”OU=BATCH3,OU=TEST,DC=Halo,DC=net” foreach ($b in $a) {…

0

Scripting Tips & Tricks: Review Your Comments

I wrote a PowerShell module recently as part of an update to a service we provide to customers. I needed to dump out all of the comments so they could be submitted for review. I wanted to ignore comment based help sections.   Here’s how I did it with the aid of RegEx…   $a…

0

Scripting Tips & Tricks: ISE – Alt + Shift + Left Mouse Button

Here's a very useful one shown to me by one of my Dutch colleagues, Stefan Stranger. I keep using this over and over, so it's going to be of value to others.   Problem You've got a block of code in your ISE that you've tabbed / indented across too much. Eh? Look at this:  …

3

Scripting Tips & Tricks: The PowerShell Script Analyzer Module

I love this new module. It makes adhering to scripting recommended practices an absolute doddle. And there's no need to go and download it from a repository as it comes bundled with v5!   Unleash the Beast Let's have a look at the cmdlets that  come with the psscriptanalyzer module:   Now, run Invoke-ScriptAnalyzer against one of my more…

2

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: CmdletBinding()

It’s been a little while since we’ve had a Scripting Tips and Tricks post… and, boy, what a topic to return on – CmdletBinding! The last Tips and Tricks post talked about using Write-Verbose in scripts and advanced functions. It’s just one of the features enabled with CmdletBinding. Here’s a snippet of what I had to say last time out:…

3

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

Scripting Tips and Tricks: Message Boxes

I used to write a lot of VBScript scripts* and a high percentage of them employed a dialogue box or two. Whether using the WScript.Shell PopUp method or the MsgBox keyword, I delighted in writing messages to screen!     How times have changed: I can't recall ever using a message box in a PowerShell script; on occasion, I use Write-Host and I certainly make use of…

1