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…


AD Cmdlet -Filter Faffing

I’m aware that I write for an international audience and I try to use international English in my posts.   When I use traditional or colloquial English I usually have a good reason for doing so. Today’s reason is because I like the alliteration that ‘Filter Faffing’ provides.   faffing – the act of making…


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…


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) {…


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…


Security Focus: Generate an Alphanumeric Password

If you have to have a password, it’s best to have a password that could contain special characters… but, what if you want to generate a password without special characters? Here’s a little function to do just that:   function New-AlphaNumericPassword { ##14 characters ##no special characters ##ASCII #48 -> 57 :: 0 -> 9…


Add Multi-Line Content to a Linux File with Add-Content

You have a large number of files to edit that are used by Linux servers. The editing and distributing of these files has to be done on a Windows platform. You want to append some multi-line detail to these files with PowerShell, but the file still needs to be compatible with Linux. Now, Add-Content with a here string would seem to…


One-Liner: PowerShell Pi Mnemonic

I love this. I came across it when looking into how to calculate Pi with PowerShell.   “$(‘How I wish I could calculate Pi better’.split(‘ ‘) | % {$_.length})”     I’ve tweaked it ever so slightly.   $(‘How I wish I could calculate Pi better’ -Split ” ” | % {[string]$a += $_.length}; $a.Insert(1,”.”))…


Profile Power: Adjust Console Opacity

WMF 5.1 comes with some cool improvements to the console. One of which I enable via my $profile, the script that runs when I start the PowerShell.exe host.     The WindowsAlpha registry value determine the opacity of the console, as does the Opacity slider below.     What’s in my $profile then?   Set-ItemProperty -Path…


Get User’s Provisioned Plans with Azure AD PowerShell Module

So… I wanted to check out what o365 licences were assigned to one of my user accounts… and… I wanted to use the Azure AD PowerShell module… I also wanted to use more ‘…’ in a post than usual!   (Get-AzureADUser -SearchString “”).ProvisionedPlans