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 WriteMember WriteProperty of a distribution group imaginatively called, er, DistributionGroup…     #Get WriteMember WriteProperty $WriteMemberGuid = “bf9679c0-0de6-11d0-a285-00aa003049e2” (Get-Acl -Path “AD:CN=Distribution Group,OU=Groups”).access | Where-Object {($_.ActiveDirectoryRights -eq “WriteProperty”) -and ($_.ObjectType…


Profile Power: Tidy Up My Personal Certificate Store

I’ve decided to do a few posts on the contents of my PowerShell profile. A profile is a script that runs when your PowerShell console starts. There is a profile for the ISE and the standard console. You can find the script location by looking at the $profile variable of the current host.   What’s in…


Security Focus: Count Vulnerabilities for Monthly Security Updates

Having a monthly single Security update makes sense. Have a cumulative quality update also makes sense. For example, two weeks ago, a customer was responding to the WannaCrypt outbreak by applying the May 2017 Monthly roll-up. Not only were the clients getting patches reaching back to October 2016, they were also getting improvements and fixes back…


Security Focus: Get CVE Information for WannaCrypt

You’ve no doubt heard that the WannaCrypt ransomware is also a worm. The propagation code exploits a patched SMB vulnerability – CVE-2017-0145. How can we use PowerShell to create a Common Vulnerabilities and Exposures (CVE) report for that vulnerability?   Set-MSRCApiKey -ApiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $cvrfDoc = Get-MsrcCvrfDocument -ID 2017-Mar $Properties = @{ Vulnerability = ($cvrfDoc.Vulnerability | Where-Object…


Use CMD to echo a Script Block to an Encoded Command

I like quirky and odd things.  Encoded commands are nothing new, but check out this method for generating one. If you echo a script block with cmd.exe /c, in a PowerShell host, you receive an encoded command (and a couple of other populated parameters) with which to call PowerShell…   cmd /c echo {while ($true) {Write-Output ` “Now…