Loop through a collection of items with the Pester TestCases parameter instead of using a foreach loop

One of the huge benefits of attending in-person technology events is getting to network with others. While at the MVP Summit last month I had a chance to demonstrate some of my PowerShell code and Pester tests to Jim Truher.  I was developing the code and tests for a session to present for the PowerShell Virtual Chapter of SQL PASS (the code and a video of that presentation can be found here). In one of my examples, I was looping through a collection of items (computer names of SQL Servers) Read more [...]

Locations for Comment-based Help in PowerShell Functions

One of the first things you'll learn when beginning with PowerShell is how to use the help system. When working from the PowerShell console, I use the help function and omit the Name parameter since it's positional and then specify the name of the cmdlet that I'm looking for help on as shown in the following example. This same type of standardized help can be added to your PowerShell functions and scripts which makes it easy for others to learn how to use them. Read more [...]

Learn to Query WMI (Windows Management Instrumentation) from PowerShell with SAPIEN WMI Explorer 2016

One of the reasons I like mentoring others and teaching them how to use PowerShell is that I spent the first third of my career pointing and clicking in the GUI. Before PowerShell was released, I had taken a three day MOC (Microsoft Official Curriculum) course on VBScript and two more days on WMI (Windows Management Instrumentation). I wrote a few VBScripts over the years but never really had a desire to learn it like I have PowerShell. I could write a VBScript if required but it seemed too developer Read more [...]

Write a GUI on Top of Existing PowerShell Functions with SAPIEN PowerShell Studio 2016

This blog article will demonstrate how to write a GUI on top of your existing PowerShell functions using SAPIEN PowerShell Studio 2016. I've previously written a couple of functions for managing SQL Server agent jobs. These two functions, Get-MrSqlAgentJobStatus and Start-MrSqlAgentJob can be found in my SQL repository on GitHub. Launch PowerShell Studio. Select file, the arrow next to new, and new form: For this particular GUI, I'll select the "Dialog Style Template" since I want a fixed Read more [...]

PowerShell Function to Check the Status of a SQL Agent Job using the .NET Framework

My previous blog article demonstrated how to start a SQL agent job using the .NET Framework from PowerShell to eliminate the dependency of needing the SQL Server PowerShell module or snap-in on the machine where the command is being run from. There's not much use of blindly starting a SQL agent job without being able to check the status of it so I decided to write another function to accomplish that task. If the machine where the code is being run from has the SQL Server PowerShell module that Read more [...]

Start a SQL Agent Job with the .NET Framework from PowerShell

As of this writing, the most recent version of the SQLServer PowerShell module (which installs as part of SQL Server Management Studio) includes cmdlets for retrieving information about SQL agent jobs, but no cmdlets for starting them. I recently ran into a situation where I needed to start a SQL agent job from PowerShell. The solution needed to be a tool that others could use who may or may not have the SQLServer module, SQLPS module or older SQL Server snap-in Read more [...]

Video: Automate Operational Readiness and Validation Testing of SQL Server with PowerShell and Pester

I recently presented a session on "Automate Operational Readiness and Validation Testing of SQL Server with PowerShell and Pester" for the PowerShell Virtual Chapter of SQL PASS. The video from that presentation is now available: https://www.youtube.com/watch?v=Ds1YO_Dpx0I Both the code and slide deck from the presentation can be found in my presentations repository on GitHub. µ Read more [...]

Webinar: Automate Operational Readiness and Validation Testing of SQL Server with PowerShell and Pester

I'll be presenting a webinar on how to "Automate Operational Readiness and Validation Testing of SQL Server with PowerShell and Pester" for the PowerShell Virtual Chapter of SQL PASS on Wednesday, November 16th at 11am CST. How do you know whether or not all of the SQL Servers in your environment are configured based on your organizations standards? How do you know whether or not they are all operating properly when maintenance is performed on the systems in your environment? During this Read more [...]

PowerShell Function to Validate Both IPv4 and IPv6 Addresses

Last week, I wrote a blog article about the IP address type accelerator in PowerShell not being 100% accurate and I demonstrated using it for parameter validation. If you want to simply validate an IP Address and return a Boolean, that's a little more complicated so I decided to write a function to perform that task along with providing detailed information about the IP address when an optional detailed parameter is specified: The IpAddress parameter can accept Read more [...]

PowerShell IP Address Type Accelerator Not 100% Accurate

Testing whether or not an IP Address is valid with PowerShell is a fairly simple process with the [ipaddress] type accelerator if your goal is to validate input for a script or function as shown in the following code example: When a valid IP address is specified, the function continues and when an invalid IP address is specified, the function terminates immediately and returns an error message: The IP Address type accelerator Read more [...]

PowerShell Function to Determine Available Drive Letters

I've recently been working on some file server drive migrations. One of the steps I needed to perform was to change the drive letter of a current drive to a different available drive letter so I decided to write a PowerShell function to accomplish the task of determining what drive letters are available. The Get-MrAvailableDriveLetter function shown in the following code example will run on systems with PowerShell version 2.0 or higher (I tested it all the way down to version 1.0, but that was Read more [...]

Create a Certificate to Encrypt MOF Passwords that’s Compatible with DSC in PowerShell version 5.0

I've previously written a blog article titled "Use a certificate with PowerShell DSC to add a server to Active Directory without hard coding a password" where I had created a certificate that was used to encrypt the password in a PowerShell version 4 DSC (Desired State Configuration) MOF file. The same procedure in PowerShell v5 generates an error stating the certificate cannot be used for encryption: ConvertTo-MOFInstance : System.ArgumentException error processing property 'Password' Read more [...]

Simplifying my PowerShell version 5 Class Based DSC Resource for Configuring Remote Desktop

Last week I wrote a blog article about a "PowerShell Desired State Configuration Class Based Resource for Configuring Remote Desktop". Since then I've discovered and learned a couple of new things about enumerations in PowerShell that can be used to simply the code even further. My original code used a couple of enumerations which I've removed to show how they can be used to further simply the code: The code shown in the previous example uses switch statements Read more [...]