Category: PowerShell

PowerShell function for creating a script module template

I'm curious to know what process others use to create new PowerShell script modules? Since the initial process of creating a PowerShell script module seems redundant and tedious, I decided to create a function that creates a template for new script modules that I create which includes creating both the script module PSM1 and manifest PSD1 files and filling in the information that I would normally include: When the previous function is run, a folder with the specified Read more [...]

PowerShell function to find information about module updates

I decided to update the one liner from my blog article last week and take it a step further by turning it into a reusable tool that displays information about module updates that are available regardless of where they were installed from. As shown in the previous results, the function lists modules that have updates available regardless of where they were originally installed from. It also lists the installed version and location Read more [...]

Update Manually Installed PowerShell Modules from the PowerShell Gallery

There are PowerShell modules that ship with Windows 10 that weren't installed from the PowerShell Gallery using PowerShellGet so they can't be updated using the Update-Module cmdlet. This also applies for any modules that you've installed manually yourself. The following PowerShell script retrieves a list of the most recent version of the modules in the all users path for PowerShell modules. It determines which ones weren't installed using PowerShellGet based on the hidden xml file that would Read more [...]

Video: PowerShell Toolmaking with Advanced Functions and Script Modules

I presented a session on PowerShell Toolmaking with Advanced Functions and Script Modules this past weekend at SQL Saturday #521 in Atlanta. I decided to make an attempt to record my session which was presented live in front of a packed room full of attendees: The recording turned out very well considering I used the built-in laptop microphone and I moved around during my presentation. The audio levels have been tweaked because they were often too low depending on how far away I was from Read more [...]

Why isn’t Test Driven Development more widely adopted and accepted by the PowerShell community?

We've all heard that TDD (Test Driven Development) means that you write unit tests before writing any code. Most of us are probably writing functional or acceptance tests after the fact because the idea of Test Driven Development isn't clearly defined, at least not in my opinion. I originally thought it meant to write thorough unit tests to test all functionality for a specific piece of code such as a PowerShell function from start to finish before writing any of the production code for the function Read more [...]

Don’t use Default Manifest Settings when Dot-Sourcing Functions in PS1 Files from a PowerShell Script Module

I briefly mentioned and demonstrated something similar to this at the end of one of my sessions at the PowerShell and DevOps Global Summit 2016. Since then, I've tested more which has led to a better solution. We've all been taught that it's best practice to use a #Requires statement in our functions that specifies the required PowerShell version along with any module dependencies, but following this best practice has one unexpected side effect when dot-sourcing functions in PS1 files from a PSM1 Read more [...]

Be Mindful of Object Types when Writing Unit Tests and Performing Operational Validation in PowerShell with Pester

I recently wrote a Pester test that performs some basic operational validation (smoke tests) of SQL Servers. I've previously written similar tests as functions as shown in my "Write Dynamic Unit Tests for your PowerShell Code with Pester" blog article, but I decided to write this one as a script with the naming convention that seems to be recommended. The name of this particular test is "Validate-MrSQLServer.Tests.ps1". You're probably thinking "Validate" isn't an approved verb and you're right, Read more [...]

Keeping Track of PowerShell Functions in Script Modules when Dot-Sourcing PS1 Files

I'm picking up where I left off in a previous blog article "Write Dynamic Unit Tests for your PowerShell Code with Pester". I'm using the dynamic Test-MrFunctionsToExport Pester test that I wrote about in that previous blog article. Currently, the test is failing for my MrToolkit module that's part of my PowerShell repository on GitHub: Based on the previous results, I can easily determine that more functions exist in the module folder than are specified in Read more [...]

Video: Creating a Custom PowerShell Toolkit to Demystify DSC

Last week, on Monday (April 4th, 2016), I presented a session at the PowerShell and DevOps Global Summit 2016 on "Creating a Custom PowerShell Toolkit to Demystify the Intricacies of Desired State Configuration". The video from that presentation is now available: https://youtu.be/fOov9gkqFHs Here’s the abstract or synopsis for this presentation: "DSC (Desired State Configuration) can be very complicated when working in an environment where nodes are set to retrieve their configuration from Read more [...]

Video: Building Unconventional SQL Server Tools in PowerShell

Last week, on Wednesday (April 6th, 2016), I presented a session at the PowerShell and DevOps Global Summit 2016 on "Building Unconventional SQL Server Tools in PowerShell with Functions and Script Modules". The video from that presentation is now available: https://youtu.be/2rEzMWdTFDk Here's the abstract or synopsis for this presentation: "Have you ever had records from a SQL Server database table come up missing? Maybe someone or some process deleted them, but who really knows what happened Read more [...]

Write Dynamic Unit Tests for your PowerShell Code with Pester

I wrote a blog article on: "PowerShell Script Module Design: Placing functions directly in the PSM1 file versus dot-sourcing separate PS1 files" earlier this year and I've moved all of my PowerShell script modules to that design and while today's blog article isn't part of a series, that previous one is recommended reading so you're not lost when trying to understand what I'm attempting to accomplish. Most unit tests that I've seen created with Pester for testing PowerShell code are very specific, Read more [...]

Converting a SQL Server Log Sequence Number with PowerShell

As demonstrated in one of my previous blog articles "Determine who deleted SQL Server database records by querying the transaction log with PowerShell", someone or something has deleted records from a SQL Server database. You've used my Find-MrSqlDatabaseChange function to determine when the delete operation occurred based on information contained in either transaction log backups or the active transaction log: You're ready to perform point in time recovery Read more [...]

Pro Tips from the Trenches: The Resolve-Path PowerShell cmdlet

You're designing a reusable tool in PowerShell and decide a function is the most appropriate type of command to accomplish the task at hand. It will accept a FilePath parameter which will be used to specify both the path and filename to a destination file. The path should already exist, but the file may or may not already exist. For simplicity, I've stripped away the complexity so the problem is more apparent. This function validates that the parent path exists and then returns the absolute path Read more [...]

Run 350 Nano Server Virtual Machines on a Lenovo ThinkPad P50 with Hyper-V in Windows 10

If you're a frequent reader of my blog articles on this site, then you're already aware that I recently purchased a Lenovo ThinkPad P50 with a Xeon CPU, 64 GB of RAM, and upgraded it to SSD hard drives as shown in my previous blog article. I tweeted that it wouldn't be complete without a few PowerShell stickers: I received a response from Jeffrey Snover wanting to know how many Nano server VM's could be run on it: I took that as a challenge and decided to spin up as many Nano server Read more [...]

Determine the Packt Publishing Free eBook of the Day with PowerShell

First of all, let me state that I'm in no way affiliated with Packt Publishing other than being a customer. They offer a free eBook each day and that information is freely available on the Internet. Like any information on the web, it's publicly available and you can read it with a web browser or with something like PowerShell. As shown in the following example, a PowerShell one liner can be used to determine their free eBook of the day: This requires PowerShell Read more [...]