Use the Abstract Syntax Tree (AST) to inspect PowerShell command syntax in scripts

I recently needed to determine the PowerShell commands and parameters used in multiple scripts. What better way to accomplish this task than to use the Abstract Syntax Tree (AST)? The Get-MrSyntax function begins by requiring at least PowerShell version 3.0. This is the oldest version that exposes the AST. The Path parameter uses ValidateScript for parameter validation to only accept files with a PS1 or PSM1 extension. The path(s) to the script files can be specified via pipeline or parameter input....

April 8, 2022 · 2 min · 340 words · Mike F. Robbins

Video: Automatically Migrate your Scripts from AzureRM to the Az PowerShell Module

As many of you know, I’m a Senior Content Developer for Azure PowerShell at Microsoft. Today we announced the Az.Tools.Migration PowerShell module which is a toolkit for automatically migrating your PowerShell scripts and modules from AzureRM to the Az PowerShell module. The video shown below demonstrates how to use this module: For more information, see the official announcement that I wrote on the Microsoft Tech Community blog site. In addition to the PowerShell module, there is also a VS Code extension for performing the migration....

September 29, 2020 · 1 min · 103 words · Mike F. Robbins

How many Services does Microsoft Azure Offer?

How many service offerings does Azure have? I’ve read anywhere from 150 to 600 and I even went so far as to ask an Azure Product Manager but didn’t receive a clear answer. What I did find out is that Microsoft maintains an Azure services directory on their Azure products website. I figured that was a good place to start looking and while the website is informative, it didn’t provide a count of the service offerings....

March 4, 2020 · 2 min · 383 words · Mike F. Robbins

AzureRM PowerShell Commands that Don’t Exist when Enabling Compatibility Aliases in the Az Module

On Twitter, I asked if anyone was still using the AzureRM PowerShell module and what was keeping them from transitioning to the Az PowerShell module. One of the responses I received was because of the amount of work and time invested in scripts based on the AzureRM module. The Az PowerShell module includes compatibility aliases for scripts written using the AzureRM PowerShell module. The compatibility aliases are enabled using the Enable-AzureRmAlias command....

February 19, 2020 · 3 min · 504 words · Mike F. Robbins

How to Install the Azure Az PowerShell Module

The Az PowerShell module was released in December of 2018 and is now the recommended module for managing Microsoft Azure. AzureRM is the previous PowerShell module for managing Azure which has been deprecated but will continue to be supported until February of 2024. Windows PowerShell 5.1, PowerShell Core 6, PowerShell 7, and higher are supported by the Az PowerShell module. Windows 10 version 1607 and higher has Windows PowerShell 5.1 installed by default....

February 10, 2020 · 4 min · 685 words · Mike F. Robbins

Setting Dependencies on the Azure PowerShell Module

I recently saw a tweet from Joel Bennett about the Az (Azure) PowerShell module being nothing more than an empty module that imports all of the modules for each Azure product. I decided to investigate. Get-Content -Path (Get-Module -Name az).Path | Select-String -SimpleMatch 'Import-Module' Joel’s statement is 100% accurate. Off-Topic: The searched for term is highlighted in each result when the previous command is run in PowerShell 7. One thing I don’t like about the Az module is the Import-Module statements use the RequiredVersion parameter....

January 28, 2020 · 2 min · 229 words · Mike F. Robbins

Initial Setup of a CanaKit Raspberry Pi 4 4GB Starter Kit

For Christmas, I received a CanaKit Raspberry Pi 4 4GB Starter Kit with Clear Case (4GB RAM). The kit contains everything you need minus an HDMI monitor and USB keyboard/mouse. It includes the Raspberry Pi 4b (I received the one with 4GB of RAM, but it’s also available with 1GB or 2GB of RAM), heatsinks, a power supply with a removable inline switch, case (I ordered the one with a clear case), case fan, micro HDMI to HDMI cable, micro SD card with NOOBS preinstalled (I ordered the one with a 32GB card), and a USB micro SD card reader in case you need to reload NOOBS on the SD card....

January 22, 2020 · 2 min · 407 words · Mike F. Robbins

Using PowerShell to Retrieve Exchange Mailbox Statistics for Office 365 Migrations

Recently, I’ve been working on trying to finish up a migration from Exchange Server 2010 to Office 365. There are potentially numerous mailboxes that aren’t used and those won’t be migrated to Office 365 because there’s no sense in paying for licensing for them. How do you determine what mailboxes are in use? First, use implicit remoting to load the Exchange cmdlets locally. Years ago, I would install the Exchange cmdlets locally, but it was brought to my attention that it’s unsupported, at least according to this article: Directly Loading Exchange 2010 or 2013 SnapIn Is Not Supported....

November 7, 2019 · 2 min · 276 words · Mike F. Robbins

PowerShell Productivity Hacks: How I use Get-Command

If you’ve been using PowerShell for very long at all, then you should already be familiar with Get-Command and Get-Help. While I like to say that Get-Command is for finding commands and Get-Help is for learning how to use those commands once you’ve found them, there is overlap between these two commands depending on how you use them. I believe in following the best practice of not using aliases or positional parameters in any code that I save or share with others, but in this blog article, I’m going to show how things work in the real world....

September 5, 2019 · 3 min · 448 words · Mike F. Robbins

Parallel and ThrottleLimit Parameters added to ForEach-Object in PowerShell 7 Preview 3

Preview 3 of PowerShell 7 was released yesterday. It can be downloaded from the PowerShell repository on GitHub. Be sure to choose the preview version for the appropriate operating system. It should go without saying that anything with preview in its name should NOT be installed on a mission-critical production system. The examples shown in this blog article are being run on a system running Windows 10 (x64). Your mileage may vary with other operating systems and/or versions....

August 21, 2019 · 2 min · 410 words · Mike F. Robbins

PowerShell Function to Find Parameter Aliases

While sitting through Jeff Hicks’ Advanced PowerShell Scripting Workshop at PowerShell on the River in Chattanooga today, he mentioned there being a “Cn” alias for the ComputerName parameter of commands in PowerShell. I’ve previously written a one-liner to find parameter aliases and at one time Microsoft had starting adding parameter aliases to the help for commands as referenced in that same blog article, but it appears that they’ve discontinued adding them to the help and removed the ones they previously added to it....

August 9, 2019 · 1 min · 163 words · Mike F. Robbins

Where are Untitled Tabs in VSCode Saved on a Windows System?

Ever wonder how VSCode (Visual Studio Code) maintains those untitled tabs between sessions? They’re stored as files underneath your user’s profile in appdata on Windows based systems as shown in the following example. Get-ChildItem -Path $env:APPDATA\Code\Backups\*\untitled -Recurse The previous command could be piped to Get-Content to view the contents of all of code in the open untitled tabs of VSCode. You could also use Select-String to find something specific. I can see that three of my open tabs contain ‘mikefrobbins’....

August 6, 2019 · 1 min · 134 words · Mike F. Robbins