This is going to be the first in a series of posts related to working with module tools. In my previous article, I talked about what tools module authors should leverage. Now I want to walk through using these tools and demonstrate how they all come together. To do this, we will be creating a new module called HideWindowsExplorerDrives. The purpose of this module is to make hiding and showing explorer drives easier. The code is beside the point. I want to focus more on how we can use some of these community projects to take our module to the next level.
The Good Stuff: Setting up a new module project using my Plaster Template.
Writing a PowerShell module is hard. A lot harder than it used to be. Honestly it’s your fault. Not just you, but the whole PowerShell community. Apparently we’re a mature language now and everybody is demanding more. I mean I was just starting to accept that fact that I have to include Pester tests, but now I need documentation too? What else does it take to write a professional quality module these days?
The Good Stuff: The skills you should be investing in to take your modules to the next level.
Whether you like it or not, at some point in your career you will be working with IPs. I recently ran into a challenge at work with variable length subnet masks that inspired this post. I needed to brush off some old networking skills and got to play with a little PowerShell along the way. With that in mind, let’s get into it.
The Good Stuff: A couple of tricks to make working with IPs a little less painful.
Dates are hard, that makes scheduling hard. Ever had someone tell you to be ready on the first Monday of the month? Don’t forget patches come out on the second Tuesday. My personal favorite is the fourth Thursday in November (Thanksgiving here in the states). While these types of dates are easy to remember, they can be hard to build automation around. Don’t worry with a couple of tricks and my helper function, I’ll make sure you never miss Mother’s Day again (second Sunday in May).
The Good Stuff: Get-SpecificDate, a function to find day of week occurrences in a given month.
Today we are going to use inheritance to create multiple DSC resource from a base class. I’m the first to admit I’m lazy and always trying to get the most bang for my lines of code. Inheritance is a great way to reduce code duplication and pretty easy once you wrap your head around it.
The Good Stuff: My DSC FileWatcher module and an example of building resources with inheritance.
I have a talk coming up on Plaster.
It’s been almost 2 months since my post on it and I’ve been playing around the last couple of days to get comfortable.
One thing that hit me was that Plaster will turn the parameters in your manifest into dynamic parameters of the
What this means is you could pull a list from anywhere and run that through a Plaster manifest, all without stepping through the wizard!
The Good Stuff: Make sure you’re using Plaster’s dynamic parameters.
While I know everyone out there writes perfect code first try, I am not so lucky. I’m a little superstitious but I think if your code works first try, it’s bad luck. We’ve all been there, you’ve been chugging away at a new project, go to run it and it blows up. Even worse, sometimes you have a resource that’s been working great, but chokes on a particular server. No way around it, debugging and troubleshooting are part of the game. This article will take your existing debugging knowledge and help you apply it to DSC.
The Good Stuff: How to Debug a DSC Resource.
This is going to be part two on DSC Classes.
Today we are going to cover a resource with more than the standard
Helper methods are a great way to organize your resource.
By making use of class properties and methods, we can create a clean resource with no code duplication.
The Good Stuff: Use helper functions to organize your Class-Based resources.
Now that we know what a PowerShell class is, it’s time we start putting them to use. Classes are new with version 5 and one of the best places for them is DSC. While the syntax maybe different, all the DSC concepts are the same. If you need a refresher on the basics of a PowerShell class, please see my previous post, Intro to PowerShell Classes.
The Good Stuff:
How to create a DSC Class-Based Resource.
This is going to be the first in a series of posts regarding classes. I want to talk more about DSC and especially some of the cool things you can do with class based resources. Before we get to the advanced use cases, we need to cover the basics.
The Good Stuff: An introduction to PowerShell classes.
I spent a few years consulting in the field and one question would always come up. How do I tell whats installed on my servers? There’s tons of advice on how to do this, some good and some bad, lets go thru it.
The Good Stuff: A function to get installed programs from the registry. Get-InstalledProgram
A hobby of my mine is to peruse the PowerShell Github page for open issues and pull requests. Its a direct way to interact with the team, see what features are being worked on and actually make a difference. I understand that putting yourself out there can be scary but everyone is incredibly friendly and its a great place to get constructive feedback. Aren’t that good at C#? Add some documentation or a Pester test. Anything helps and there’s a ton to do.
The Good Stuff: Go to the PowerShell Github Page and start contributing!
If you haven’t yet, I would definitely check out Plaster. Plaster is a PowerShell scaffolding module. What that means for you is that its an easy way to keep your modules and functions consistent and following best practices. Its fully customizable and you can get started in just a few minutes.
The Good Stuff:
Go check out plaster, a template-based file and project generator written in PowerShell. Plaster Project Page
I think one of the biggest hurdles learning PowerShell is trying to find what command to run. What i use to do is read a different help file every morning. Now i don’t expect anyone to be able to look at a help file once and instantly know the ins and outs of a command. But forcing yourself to read a random help file can get the mental juices flowing. The goal of this script is to just start learning what PowerShell CAN do.
The Good Stuff: A script to get a random help file. Open-PSCommandHelp.ps1.
Lets be honest, before PowerShell the windows command line was a joke and the Linux guys were running circles around us. One of the best functions from Linux is sudo. Sudo is used when you need to run a command with elevated privileges, similar to running a program as administrator in windows. Here’s my implementation of sudo for PowerShell.
The Good Stuff: A script that implements sudo in Powershell. Start-ElevatedProcess.ps1