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      


Profile Power: Default Parameter for Format-Table and Format-Wide

I’m lazy. When I run Format-Table and Format-Wide, the effort of typing -A and pressing Tab to give me -AutoSize weighs heavy on my fingers! And, so it is that I use the $PSDefaultParameterValues variable, in my PowerShell profile, to automatically add the -AutoSize parameter every time I run Format-Table or Format-Wide.   $PSDefaultParameterValues[‘Format-[wt]*:Autosize’] = $true   And, it’s…


Get Active Directory “Write Members” WriteProperty

A messaging colleague asked how to check which principals have the Write Members permission on distribution lists. I sent him a sample of how to query the WriteProperty for the Member property of a distribution group imaginatively called, er, DistributionGroup…     #Get Member WriteProperty $MemberGuid = “bf9679c0-0de6-11d0-a285-00aa003049e2” (Get-Acl -Path “AD:CN=Distribution Group,OU=Groups”).access | Where-Object {($_.ActiveDirectoryRights -eq…