I am largely self-taught and/or google-taught. What this means is that my coding practices would make a professional coder laugh and cry in equal measure. It is improving gradually, but usually only when something breaks, and the code was such a mess that I had to redo chunks of it. Learning from our mistakes is what makes humans awesome, and it would be a shame to let this evolutionary leap go to waste by not doing things poorly now and then. Posting it here will help because I’ll go the extra yard to make it neat and/or presentable and in some cases that I may have already planned, rewrite huge sections of things both for production and posting.
A side benefit of posting it is that one day, someone might get stuck and search for a solution for something and find one here. That would be awesome.
Alongside the posts about functions and modules, I will also throw in some of my processes, my test environment and tools, and random brain-dribblings.
If you find any of my scripts incorrect, heinously incorrect or inefficient, let me know in the comments. I would be surprised if I don’t have at least one of each category at any given time.
One thing you might think from seeing both the environmental setup and the number of task-specific scripts is that I run my work domain with an iron fist, but it’s not like that. Not entirely like that anyway. I realised long ago that people, myself included, would always do something the quick way. And worse still, once they’re used to the quick way it takes Inception levels of effort to change it. If the quick way of doing something is incorrect, the best way to stop people doing it is to create an easier or quicker way that does everything properly.
And that’s what these scripts are primarily for. So other people don’t break everything. The speed, convenience and ‘who did that?’ logging are a bonus.
In my posts when I explain how to do something, I’m not going to explain all the other ways of doing something, there are plenty of sites that already do that way better than I ever could. One thing that I haven’t seen many other sites doing is applying this stuff against a real world environment. Most of the official stuff gets you to use a lot of commands, but the real-world experience you get is a bit superficial. If things went as smoothly as an MSCE lab implies, there would be a lot less IT staff needed around the world.
My scripts are designed around the fact that the data we get in is often trash, things we create might get a major name change 3 minutes after creation, and nothing is ever simple. Every time someone requests something off-policy, the hairs on my neck stand up. It normally ends with me coding around these exceptions. So I try to code around as much stuff as I can straight off the bat. A prime example of this is my Resolve-User function, which now gets into most of my larger scripts. It means that aside from typos, I can accept user names in any of the common varieties (display name, samaccountname, email, UPN, firstname lastname, etc.), and it will spit out the appropriate user objects.