Category: PowerShell

Video: Writing Award Winning PowerShell Functions and Script Modules

Last month I presented a session on Writing Award Winning PowerShell Functions and Script Modules at the PowerShell + DevOps Global Summit in Seattle, Washington. The session seemed to be well received by the audience based on the feedback that I received from the attendees. The session was also completely full. I'm glad it was recorded so anyone who was unable to attend can watch it. The video from this presentation is now available. The Read more [...]

PowerShell Core 6: ValidatePattern Custom Error Messages

Last week, I received a comment on my previous blog article from fellow Microsoft MVP Joel Bennett which referenced using an ErrorMessage parameter similar to how ValidatePattern works in PowerShell Core version 6. I knew I'd seen some discussion about this on GitHub, but I wasn't aware that it had made it into the production release. Joel's message is shown in the following image. I had to figure out how to use custom error messages with ValidatePattern. After all, that was the whole Read more [...]

Simplifying Parameter Validation in PowerShell with Private Functions

In my previous blog article, I described how to move code from ValidateScript to a private function for parameter validation in PowerShell. This all came about from a question I received in one of my sessions at the PowerShell + DevOps Global Summit a couple of weeks ago. I enjoy following up with attendees of my presentations when they have questions so I sent a message and a link to my previous blog article to the person who asked if that was possible. They responded by asking if it was possible Read more [...]

Moving Parameter Validation in PowerShell to Private Functions

While presenting one of my presentations at the PowerShell + DevOps Global Summit last week, I demonstrated why you wouldn't want to use ValidatePattern for parameter validation because of the useless error message that it returns when the input doesn't match the regular expression that's being used for validation. I then demonstrated how ValidateScript could be used to build a better ValidatePattern. I have an older blog article that details this process if Read more [...]

Remotely Uninstall ESET Antivirus with PowerShell

Recently, one of the companies that I provide support for switched from using ESET to a new antivirus vendor. The problem is that all of their servers had both ESET File Security and the ESET Remote Administrator Agent installed which needed to be uninstalled before installing the new antivirus agent. I determined that the following commands could be used to uninstall the applications. Running msiexec.exe /? shows the available options. Based on this information, Read more [...]

Adding Multiple Parameter Sets to a PowerShell Function

Sometimes you need to add more than one parameter set to a function you're creating. If that's not something you're familiar with, it can be a little confusing at first. In the following example, I want to either specify the Name or Module parameter, but not both at the same time. I also want the Path parameter to be available when using either of the parameter sets. Taking a look at the syntax shows the function shown in the previous example does indeed have two Read more [...]

Using Plaster to create a PowerShell Script Module template

I have a function in my MrToolkit module named New-MrScriptModule that creates the scaffolding for a new PowerShell script module. It creates a PSM1 file and a module manifest (PSD1 file) along with the folder structure for a script module. To reduce the learning curve of Plaster as much as possible, I'm simply going to replace that existing functionality with Plaster in this blog article. Then moving forward, I'll add additional functionality. For those of you who aren't familiar with Plaster, Read more [...]

Temporarily Disable the Azure AD Connect Accidental Deletion Protection Feature with PowerShell

You've implemented Azure AD Connect to synchronize accounts in your on-premises Active Directory environment to Azure AD. If you took the defaults while running the setup wizard for Azure AD Connect, then everything in your Active Directory environment is synchronized. If you decided to filter the synchronization later to only specific OU's (Organizational Units) in your Active Directory environment, you could run into a scenario where the number of deletions exceeds the default threshold of 500 Read more [...]

The PowerShell Iron Scripter: My solution to prequel puzzle 3

I've been working through the Iron Scripter 2018 prequel puzzles which can be found on's website. In puzzle 3, you're asked to create a "reusable PowerShell artifact". To me, that almost always means a PowerShell function. One requirement is to pull information from the RSS feed. Invoke-RestMethod which was introduced in PowerShell version 3.0 is the easiest way to accomplish that task. You're also asked to display the returned information in a way that allows the Read more [...]

Help in PowerShell Core is independent of help in Windows PowerShell

You've decided to install PowerShell Core on your Windows system. First of all, keep in mind that PowerShell Core version 6.0 is not an upgrade or replacement to Windows PowerShell version 5.1. It installs side by side on Windows systems. Being aware of this makes what is shown in this blog article make more sense, otherwise it can be confusing. Based on the response to a tweet of mine from Don Jones, it appears that I’m not the only one who thought PowerShell Core should have been version 1.0 Read more [...]

The PowerShell Iron Scripter: My solution to prequel puzzle 2

As I mentioned in my previous blog article, each week leading up to the PowerShell + DevOps Global Summit 2018, will be posting an iron scripter prequel puzzle on their website. As their website states, think of the iron scripter as the successor to the scripting games. If you haven't done so already, I recommend reading my solution to the Iron Scripter prequel puzzle 1 because some things are glossed over in this blog article that were covered in detail in that previous one. Prequel Read more [...]

The PowerShell Iron Scripter: My solution to prequel puzzle 1

Each week leading up to the PowerShell + DevOps Global Summit 2018, will be posting an iron scripter prequel puzzle on their website. As their website states, think of the iron scripter as the successor to the scripting games. I've taken a look at the different factions and it was a difficult choice for me to choose between the Daybreak and Flawless faction. While I try to write code that's flawless, perfection is in the eye of the beholder and it's also a never-ending moving target. Read more [...]

Use PowerShell to create a bootable USB drive from a Windows 10 or Windows Server 2016 ISO

It seems as if every time I need to reload a physical system, I'm searching the Internet to find a way to create a bootable USB drive from a Windows 10 or Windows Server 2016 ISO. I always seem to find tutorials that are using a process that's almost 20 years old. They have me using the diskpart command line utility. Diskpart which initially shipped with Windows 2000, reminds me way too much of its predecessor, the fdisk command line utility. The PowerShell commands in this blog article are written Read more [...]

PowerShell Compare-Object doesn’t handle null values

I thought I'd run into a bug with the Compare-Object cmdlet in PowerShell version 5.1 earlier today. Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null. At line:1 char:33 + Compare-Object -ReferenceObject $DriveLetters -DifferenceObject $Driv ... + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand Running Read more [...]

PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell is the featured book on Leanpub

Learning PowerShell seems to be a hot topic for the new year. My PowerShell 101 book was the number one bestseller on Leanpub earlier this week and now it's the featured book on their website. Going to the homepage on their website, shows the book is indeed the currently featured one. I would also like to thank Tommy Maynard for the technical editing he performed on the book. If you're not following him on Twitter or reading the articles on his blog site, you should be. µ Read more [...]

Using PowerShell to Check Remote Windows Systems for CVE-2017-5754 (Meltdown) and CVE-2017-5715 (Spectre)

The Microsoft Security Response Center has released a PowerShell module named SpeculationControl that can be used to check for the CVE-2017-5754 (Meltdown) and CVE-2017-5715 (Spectre) vulnerabilities. The SpeculationControl module can be installed from the PowerShell Gallery with Install-Module which is part of the PowerShellGet module that ships natively with PowerShell version 5.0, but can be installed on PowerShell version 3.0 and higher. Running Read more [...]