Fun & Frolics: Generate a 0 and 1 Screen Stream

What a ridiculous title! Believe me, the post gets even more ridiculous. Anyway, it’s a bit of fun!   I had to do the following for a conference I recently spoke at…   function ExfiltrateData { Write-Output ” ” 1..900 | % {Write-Host “$(Get-Random -Minimum 0 -Maximum 2)” -NoNewline } 1..14 | % {Write-Host “$(Get-Random…


Module Manifest – ScriptsToProcess

Here’s a nice little trick. When creating a PowerShell module you can specify a list of scripts to process when the module is loaded. You can use the scripts for validation or prerequisite checking. Here’s a nice little example… In the .psd1* file for the module, i.e. the manifest, add (or uncomment) a line to look…



Here’s a function I use quite a lot. Now, I know it’s old-world (ASM rather than ARM) in terms of Azure, but I still have a lot of old-world, cloud services. In fact, a lot of them were built by the following script and the function should be considered as partner code.   Build an…


Security Focus: Get Mail Enabled Admin Users

Browsing the internet with an admin account is a very, very bad thing to do. Using an admin account to send / receive email is also a very, very bad thing. Why? Well you expose the credentials to a high risk of being stolen and used to compromise your enterprise. Want do to some checks against Active…


Try to Catch Error Exception Types

When error handling with Try, Catch, Finally you can create conditional catch statements to target specific exceptions. Here’s an example.   try { $wc = new-object System.Net.WebClient $wc.DownloadFile(“”) } catch [System.Net.WebException],[System.IO.IOException] { “Unable to download MyDoc.doc from } catch { “An error occurred that could not be resolved.” }   Look at the first…


Back to Basics: Generate Monthly Report Folders

I’m always using PowerShell to just, well, help out with day to day stuff I have to do. The other week I used PowerShell to generate a bunch of folders for 2017 that I’ll use to store my expense receipts in. All very mundane; all completed in milliseconds. $a = 1..12 | % {(Get-Date -Month $_ -f…


Security Focus: Enable / Disable MFA on Azure AD Admin Account

Last week I presented a little function that I use to reset my Azure AD admin account passwords. This week I want to show how to enable / disable Multi Factor Authentication on an Azure AD account.   Enable $St = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement $St.RelyingParty = “*” $Sta = @($St) Set-MsolUser -UserPrincipalName -StrongAuthenticationRequirements $Sta…


Security Focus: Update Azure AD Admin Account Password

Got to love this cmdlet – Update-AzureADSignedInUserPassword ! I use it to update admin credentials on Azure AD instances that I only occasionally use. This avoids expiry aches and pains.   Want to take a look? First up, go get yourself a copy of the AzureAD module from PSGallery… Find-Module -Name AzureAD Install-Module -Name AzureAD -Verbose   Now, I…



After showing a customer the PI static method of System.Math, they asked, “how do I get more digits?”.   A quick bit of lateral-thinking, i.e. cheating, later and a with more than a nod to the hard work done by the folks at, here’s the wonderfully named Get-OneMillionDigitsOfPi function.   function Get-OneMillionDigitsOfPi { (Invoke-WebRequest -Uri “”).Content…


Use PowerShell to Show User Rights Assignments Set by Group Policy

Here’s one I came across whilst performing some Group Policy troubleshooting…   Get-CimInstance -Query “Select * from RSOP_UserPrivilegeRight where precedence=1” -Namespace root\rsop\computer | Select-Object UserRight,AccountList   13   It shows the UserRight set by Group Policy and who has it.