PowerShell Snippet: Add User to Local Group on Machine PLUS Random Rantings

Hello!

First day of my holiday, so naturally I’m up writing blog posts. And unfortunately, rather like my holiday, this post will be brief.

Every time I step off some public transport, I get this nagging feeling that I may have left something behind, even though I always take stock before disembarking the train/tube/bus. I largely suspect that what I have left behind is a bit of my soul, such is my loathing for public transport. I’ve even got to the point of leaving work early to give me enough time to walk through London as opposed to getting the tube.

What’s this got to do with PowerShell? Well, much like public transport, repetitive, tedious tasks like clicking through the UI also takes a toll on me equal to that of traveling public transport. However, writing some PowerShell to automate a process takes very little time and speeds up the process of getting a boring job done.

Like recently I had to add a user to a local group. A one off task yes, but still had to be done on over 30 machines. So rather than click through the UI like a chump that many times, I wrote a script that would do it for me. And but so being the guy I am I stuck it on a public gist and am blogging about it here.

I’ll probably make a function out of it for those people that are too lazy to do it themselves.

This brings me onto something though: I did a quick Google for a script like the one what I wrote above, and I came across someone looking for the same thing, but in one line. And it got me thinking: as efficient as having one line of PowerShell is, chances are it won’t contain any error handling. As a guy who’s worked on builds and looked though thousands of rows of verbose output just to find that ONE pertinent line that tells me exactly what the problem is, I think it would be remiss to leave a process to a single line and just hope that an error is handled.

Leave a Reply

Your email address will not be published. Required fields are marked *