Splitting the PowerShell PSModulePath Cross-Platform

The $env:PSModulePath environment variable contains a list of directory locations that PowerShell searches to locate modules. $env:PSModulePath When you’re trying to determine what paths are part of the $env:PSModulePath environment variable in PowerShell, you’ll find that most examples split the results on the semicolon (;) character to return each path on a separate line. $env:PSModulePath -split ';' Another variation is to use the Split method instead of the operator. $env:PSModulePath.Split(';') Splitting on a semicolon was a great solution back in the day of Windows (only) PowerShell....

February 17, 2023 · 2 min · 276 words · Mike F. Robbins

Enable PowerShell remoting on ArcoLinux

PowerShell is a cross-platform scripting language that runs on Windows, Linux, and macOS. ArcoLinux is a rolling release Linux distribution based on Arch Linux. Prerequisites ArcoLinux was installed using the ArcoLinuxL ISO with the easy installation option. The examples shown in this article were performed using Xfce Terminal. ArcoLinux was fully updated using the sudo pacman -Syu command. Installation Verify that you have PowerShell installed: pwsh --version If you receive the error: command not found, see Install PowerShell on ArcoLinux to install PowerShell....

August 25, 2022 · 4 min · 712 words · Mike F. Robbins

Install Visual Studio Code (VS Code) on ArcoLinux

Visual Studio Code (VS Code) is a powerful, lightweight, and cross-platform source code editor. ArcoLinux is a rolling release Linux distribution based on Arch Linux. Prerequisites ArcoLinux was installed using the ArcoLinuxL ISO with the easy installation option. The examples shown in this article were performed using Xfce Terminal. ArcoLinux was fully updated using the sudo pacman -Syu command. Installation You could use the pacman or paru command. I chose to use the pamac command....

July 28, 2022 · 2 min · 218 words · Mike F. Robbins

Install PowerShell on ArcoLinux

PowerShell is a cross-platform scripting language that runs on Windows, Linux, and macOS. ArcoLinux is a rolling release Linux distribution based on Arch Linux. Like other Arch-based Linux distributions, ArcoLinux uses pacman for its package manager. Prerequisites ArcoLinux was installed using the ArcoLinuxL ISO with the easy installation option. The examples shown in this article were performed using Xfce Terminal. ArcoLinux was fully updated using the sudo pacman -Syu command. Your mileage may vary with other operating systems, versions, distributions, desktop environments, ISO’s, terminals, installation options, package managers, and versions of PowerShell....

June 30, 2022 · 2 min · 347 words · Mike F. Robbins

Use PowerShell to determine the Windows version on DVD, ISO, or USB installation media

You’re preparing to load an operating system. You find installation media for an unknown version of Windows. It’s not labeled. How do you determine the version of Windows on the installation media? You can use the Get-WindowsImage cmdlet to determine the Windows version of installation media. This cmdlet is part of the Dism PowerShell module. It can be used with Windows PowerShell 5.1 and PowerShell 7 on Windows operating systems....

June 16, 2022 · 1 min · 74 words · Mike F. Robbins

Using the conditional ternary operator for simplified if/else syntax in PowerShell 7

The conditional ternary operator is a feature added to PowerShell in version 7. You can use it as a simplified version of if/else. The syntax for the ternary operator takes three operands: A condition to evaluate followed by a question mark (?). An expression to execute if the condition is true, followed by a colon (:). And finally, an expression to execute if the condition is false. <condition-to-evaluate> ? <expression-to-execute-if-true> : <expression-to-execute-if-false> The examples in this blog article were tested using Windows 11 version 21H2, PowerShell version 7....

June 9, 2022 · 2 min · 297 words · Mike F. Robbins

Formatting PowerShell 7 code like Kusto Query Language

An obscure feature that was added to PowerShell in version 7 is the ability to specify the pipe character on the next line similar to the syntax for Kusto Query Language (KQL). Get-Command -Name Get-Help, Get-Command, Get-Member -PipelineVariable results | Select-Object -ExpandProperty ParameterSets | Select-Object -ExpandProperty Parameters | Where-Object Aliases | Select-Object -Property @{label='CmdletName';expression={$results.Name}}, Name, Aliases | Sort-Object -Property CmdletName, Name -Unique | Format-Table -GroupBy CmdletName Pasting code in the PowerShell console with pipes at the beginning of lines only works when using Ctrl+V....

June 2, 2022 · 1 min · 99 words · Mike F. Robbins

Format the output of a string in multiple columns with PowerShell

In my previous blog article, I used the PowerShell Format-Wide cmdlet to format the output of a string in multiple columns. While Format-Wide isn’t a command that I’ve used extensively, the behavior wasn’t what I expected. When you pipe object-based output other than a string from any PowerShell command to Format-Wide, it produces the desired results. Get-PSDrive | Format-Wide -Column 2 I’ll pipe the following to Get-Member to confirm that it’s a string....

May 26, 2022 · 2 min · 229 words · Mike F. Robbins

Use the Abstract Syntax Tree (AST) to list parameters and variables in PowerShell functions

One thing I’ve missed during the past couple of years with virtual-only conferences is the hallway track. While at the PowerShell + DevOps Global Summit 2022, there was a discussion about using PascalCase for parameter names and camelCase for user-defined variables in your PowerShell functions. Specifying different casings depending on the usage seems like a great idea. Determining where you defined your variables would be self-explanatory. The only problem is you need something to verify that you’ve specified them in the correct case....

May 12, 2022 · 3 min · 634 words · Mike F. Robbins

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