Author: Mike F Robbins

Mike F Robbins is a Microsoft MVP on Windows PowerShell and a SAPIEN Technologies MVP. He is a co-author of Windows PowerShell TFM 4th Edition and is a contributing author of a chapter in the PowerShell Deep Dives book. Mike has written guest blog articles for the Hey, Scripting Guy! Blog, PowerShell Magazine, and PowerShell.org. He is the winner of the advanced category in the 2013 PowerShell Scripting Games. Mike is also the leader and co-founder of the Mississippi PowerShell User Group. He blogs at mikefrobbins.com and can be found on twitter @mikefrobbins.

Video: Finding Performance Bottlenecks of Windows Based Systems with PowerShell

Earlier this month, I presented a session on Finding Performance Bottlenecks with PowerShell at the PowerShell + DevOps Global Summit 2019 in Bellevue, Washington. The session seemed to be well received by the audience based on the feedback that I received from the attendees. The video from this presentation is now available https://www.youtube.com/watch?v=zaHZOffoZyE The code and slides used during the demonstration can be found in my presentations repository on GitHub. µ Read more [...]

Using the AST to Find Module Dependencies in PowerShell Functions and Scripts

Earlier this week, Chris Gardner presented a session on "Managing dependencies in PowerShell" for the Mississippi PowerShell User Group. I mentioned that I had written a function to retrieve PowerShell module dependencies that's part of my ModuleBuildTools module. Get-MrAST is one of the primary functions that numerous other functions in the module are built on. It retrieves the AST from one or more PS1 and/or PSM1 files, script blocks, or random arbitrary code. It Read more [...]

Sort PowerShell Results in both Ascending and Descending Order

A few weeks ago I was trying to figure out how to sort something in PowerShell with one property sorted descending and another one ascending. How to accomplish this was hiding in plain sight in the help examples for Sort-Object, but I thought I would documented it here for future reference. Use the Property parameter with a hash table to specify the property names and their sort orders. This same command can be written on one line. It Read more [...]

Use PowerShell to Identify the Process ID for SQL Server Services

I recently saw a blog article on "How to Identify Process ID for SQL Server Services? – Interview Question of the Week #185" written by Pinal Dave. While his answer is simple with TSQL, what if you're not a SQL guy? You can also retrieve this information with PowerShell from Windows itself. When it comes to retrieving information about Windows services with PowerShell, the first command that comes to mind is Get-Service. Unfortunately, Get-Service doesn't return the process id for services. Read more [...]

Enable Tab Completion in VSCode for a PowerShell ISE like Experience

I'm using VSCode for all of my PowerShell development at this point. I reloaded my system from scratch on March 13th of this year. Yesterday was the first time I've opened the PowerShell ISE since then and it was only to determine if something worked differently between the two (I tweeted this out yesterday). One of the common problems I hear about and have experienced myself with VSCode (Visual Studio Code) is that tabbed expansion of command and parameter names doesn't work like it does in the Read more [...]

Run SQL Server PowerShell Cmdlets as a Different User

One of the ways I practice the principal of least privilege is by logging into my computer as a domain user who is also a standard local user. I typically run PowerShell as a domain user who is a local admin and elevate on a per command basis using a domain account with more access only when absolutely necessary. The problem I've run into is neither the account I'm logged into my computer as or the one I'm running PowerShell as has the ability to execute SQL queries that I need to run against various Read more [...]

Audit Membership of the Local Admins Group with PowerShell

Recently, I needed to make sure that specific accounts were members of the local administrators group on several servers along with making sure that no other users were members of it. PowerShell version 5.1 introduced a module named Microsoft.PowerShell.LocalAccounts that contains the following commands for managing local users and groups. Checking the group membership is as easy as running Get-LocalGroupMember within the script block of Invoke-Command and Read more [...]

Backup and Synchronize VSCode Settings with a GitHub Gist

Earlier this year, I watched a recording of the January 2019 Arizona PowerShell User Group meeting where Tim Warner presented a session on "Easing your transition from the PowerShell ISE to Visual Studio Code". One of the things Tim demonstrated was a VSCode extension named "Settings Sync" where you can synchronize your VSCode settings to and from a GitHub Gist. While it seems to be designed to synchronize your settings between multiple computers, I recently found out that it can also be a lifesaver Read more [...]

The Noobs Guide to Installing Docker Desktop for Windows

I recently came across an article on "Running PowerShell Core in a Container". This article tweaked my interest because it was a simple way to run PowerShell in a clean and isolated environment that could be used for testing without the need to spin up an entire VM. It could also be recreated much easier than an entire VM. The examples in the previously referenced article use a command (docker.exe) which I didn't have on my machine so the first order of business was to figure out how to run Docker Read more [...]

PowerShell Tokenizer more Accurate than AST in Certain Scenarios

As many of you know, I've been working on some module building tools. One of the things I needed was to retrieve a list of PowerShell modules that each function required (a list of dependencies). This seemed simple enough through PowerShell's AST (Abstract Syntax Tree) as shown in the following example. The modules that are retrieved by the AST are simply the ones specified in a functions Requires statement. What if someone forgot to add a required module to Read more [...]

My Solution to Iron Scripter 2019 Preparatory Challenge 1

Anyone who has competed in the scripting games before knows that I'm always looking for a challenge when it comes to writing PowerShell code. While the scripting games haven't been held in the last several years, they've somewhat been replaced by the Iron Scripter competition at the PowerShell + DevOps Global Summit and 2019 is shaping up to be no different. Think you've got skills? Bring them on! and Get-Involved. Whether you've previously competed or not, you should definitely head over to IronScripter.us Read more [...]

Unexpected Results when Comparing Different Datatypes in PowerShell

Earlier this week, I saw a tweet from a fellow PowerShell community member who mentioned PowerShell was returning inaccurate results. The command shown in the tweet was similar to the one in the following example. Why would results be returned where "IsFramework" is true when the command is filtering them down to only the ones that are false? I knew exactly what the problem was because I've been bit by it more times than I care to remember. Piping the Get-AppxPackage Read more [...]

What’s a PowerShell One-Liner & NOT a PowerShell One-Liner?

Lately, I've seen a few examples of commands that aren't PowerShell one-liners being passed off as such by people in the PowerShell community who "should" know better. If I were interviewing someone who claimed to be a PowerShell expert with more than five years of experience, I would definitely ask these types of questions. Example 1 - The following command is a PowerShell one-liner? (True or False) Example 2 - The following command is a PowerShell one-liner? Read more [...]

Return a List of the Private Functions in a PowerShell Module

In my quest to build a PowerShell module to convert a non-monolithic PowerShell module from development to a monolithic one for production, I wanted some way to validate that all of the functions were indeed migrated. While I'm pointing my tools to the public and private sub-folders within my development module and that should get them all, how can you be sure especially when a module may not have any private functions? Determining the publicly accessible functions for a module is easy enough Read more [...]

Resolving Microsoft SQL Server Error 4064 with PowerShell

Recently, a fellow IT Pro contacted me and stated they were unable to login to one of their SQL Servers using Windows Authentication. The following error was generated when attempting to login to SQL Server Management Studio (SSMS). Their exact words were "I think we have a permissions problem". Clicking on the "Show technical details" icon at the bottom of that error message showed the following information. You can work around this problem by clicking on the "Options >>" button: Then Read more [...]

Finish the year off helping others in the PowerShell Community

If you follow my blog, then I'm sure you're aware that earlier this year I embarked on a project to help others get started with PowerShell. I leveraged the contacts I'd made over the years in the PowerShell community and created a book with many of them, named "The PowerShell Conference Book". We all donated our time as 100% of the royalties go towards funding scholarships for the OnRamp track at the PowerShell + DevOps Global Summit. So far, we've fully funded three scholarships ($4,000 Read more [...]