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.

Install PowerShell 7 with Jeff Hicks’ PSReleaseTools Module

PowerShell version 7 is currently in preview and while it can be installed on Windows, Linux, and macOS, the examples shown in this blog article focus on installing it on a Windows based system, specifically Windows 10 using Windows PowerShell version 5 or higher which ships by default with Windows 10. Your mileage may vary with other operating systems, other versions of Windows, and/or other versions of Windows PowerShell. The easiest way that I've found to install the preview of PowerShell version Read more [...]

Import a Hyper-V Virtual Machine with PowerShell

I recently ran into a problem where an exported VM from Windows Server 2016 running Hyper-V wasn't able to be imported on Windows Server 2019 running Hyper-V. When attempting to perform the import, the GUI stated "No virtual machines files found" as shown in the following image. This problem may have been due to using Hyper-V manager on a remote system running Windows Server 2012 R2, although the same system was used for the export. Since the Hyper-V servers themselves were installed with Read more [...]

Determine the Generation of a Hyper-V VM with PowerShell

Ever need to determine what generation all of the virtual machines are on your Hyper-V servers? This is simple using the Get-VM command that installs as part of the Hyper-V module for Windows PowerShell. While the previous command will work on both clients and servers, the following command could also be used on a Windows server. The generation of the VM is one of the properties from the results of Get-VM. The Read more [...]

Mitigating BlueKeep with PowerShell

When it comes to security, most people normally approach it at one extreme or the other. Some people do nothing and don't worry about it. All I can say for those folks is good luck with that and I hope your resume is updated. Others go into full blown panic mode, especially those who don't take the time to understand vulnerabilities. Many security folks and articles on the Internet don't help much either because they often blow things out of proportion which puts many of the people in the second Read more [...]

Find an Application that runs as a Service in your Environment with PowerShell

I recently worked with a vendor to remove an old application that was no longer being used from a server in one of my customer's environments. While many applications may be left to die on the server long after they're needed, this particular one transmitted data to a partner company so it definitely needed to be removed. The problem is the application was so old that no one knew which server of the hundreds of servers it was running on. The partner company was able to provide the display name Read more [...]

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 [...]