Category: PowerShell

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

PowerShell Desired State Configuration Class Based Resource for Configuring Remote Desktop

Prior to PowerShell version 5 being released, I had written a PowerShell version 4 compatible DSC (Desired State Configuration) resource named cMrRDP for configuring Remote Desktop. It can be found in my DSC respository on GitHub. The recommendation at that point was to use the letter "c" as the prefix for community created DSC resources. The current recommendation is to no longer use the "c" prefix for DSC resources. Steven Murawski wrote a blog article titled "DSC People - Let's Stop Using 'c' Read more [...]

Store and Retrieve PowerShell Hash Tables in a SQL Server Database with Write-SqlTableData and Read-SqlTableData

In my blog article from last week, I demonstrated using several older open source PowerShell functions to store the environmental portion of the code from operational validation tests in a SQL Server database and then later retrieve it and re-hydrate it back into a PowerShell hash table. Earlier this week, a new release of the SQLServer PowerShell module was released as part of SSMS (SQL Server Management Studio): It includes three new cmdlets, two of which can be used to store and retrieve Read more [...]

Store Environmental Code in a SQL Server Database for PowerShell Operational Validation Tests

I've previously published articles on separating environmental code from structural code for both DSC (Desired State Configuration) and Operational Validation or Readiness Tests. This article picks up where I left off last week in "Separating Environmental Code from Structural Code in PowerShell Operational Validation Tests". As many existing open source PowerShell functions as possible have been used in the examples shown in this blog article instead of re-inventing the wheel and rewriting everything Read more [...]

Separating Environmental Code from Structural Code in PowerShell Operational Validation Tests

Do you ever feel like you're writing the same operational validation or readiness test over and over again? I'm not sure about you, but I don't like repeating myself by rewriting the same code because it creates a lot of technical debt. There has to be a better way <period>. Why not take the same thought process from DSC (Desired State Configuration) and separate the environmental portion of the code from the structural portion and apply it to operational tests so the same or similar code isn't Read more [...]

Use PowerShell and Pester for Operational Readiness Testing of Altaro VM Backup

I've recently been working with Altaro VM Backup and I must say that I've been very impressed with the ease and simplicity of the product. The back-end portion of the product can run on a virtual or physical server with or without the GUI (Server Core is supported). It can backup to just about any type of drive (local disk, UNC path, USB drive, etc). It doesn't require SQL Server. In my environment, adding a Hyper-V server (running Windows Server 2012 R2) installed a service on the Hypervisor, but Read more [...]

Learning Existing and Setting Up New Keyboard Shortcuts in Visual Studio Code for the PowerShell Enthusiast

I've recently made myself start using Visual Studio Code for writing some of my PowerShell code and I thought I would share a few of the tips that I've learned. If you haven't read my blog article titled "Use the PowerShell Console from within Visual Studio Code", I definitely recommend taking a look at it as today's blog article assumes that you've already made those modifications to your Visual Studio Code environment. When you first open Visual Studio Code, it defaults to plain text (I haven't Read more [...]

Speaking on PowerShell Toolmaking this weekend at {dev = data} DAY Birmingham 2016

I'll be presenting a session on PowerShell Toolmaking with Advanced Functions and Script Modules this Saturday, August 20th at {dev = data} DAY Birmingham 2016. Here's what you can expect from my session: "Transitioning from writing PowerShell one-liners and basic scripts to creating reusable PowerShell tools with advanced functions and script modules can be a daunting task and with all the different ways that you’ll find on the Internet to accomplish the same task, it can definitely seem Read more [...]

Use the PowerShell Console from within Visual Studio Code

I recently revisited Visual Studio Code. I was looking for a markdown editor and remembered seeing a tweet a few weeks ago saying that VS Code could be used to edit markdown. It supports markdown by default, although I would recommend adding a spell check extension to it. I thought that it would be convenient if I could write my PowerShell code right from within the same interface that I'm writing other things such as markdown. One of the problems that I previously experienced with VS Code is Read more [...]

Speaking on both PowerShell and DSC at SQL Saturday Baton Rouge 2016 this Weekend!

Although PowerShell has been around for 10 years now, there are still some who are just getting started with it. There are several categories that new comers fit into, some are just starting out in their career, others may be career changers, and others may have been in the industry for a number of years and are finally trying to embrace PowerShell. Regardless of which category you fit into, I'll be presenting a session on "PowerShell Fundamentals for the Absolute Beginner" at SQL Saturday #515 Read more [...]

Something to -notlike about the -like operator in PowerShell

I recently ran into a problem with the PowerShell like operator that I wanted to share since what's occurring may not be immediately apparent. The like operator allows for comparison tests of strings using wildcard characters instead of exact matches. I think of it being similar to the match operator except like uses simple wildcards instead of regular expressions. Easy enough, right? A string on the left and another string with wildcards on the right. If Read more [...]