r/PowerShell • • Apr 25 '19

Skills milestone achieved!

When I came into my first IT job five years ago, the place was a mess. GPOs were broken, random bat files everywhere, no model-independent OS deployment in place, lots of manual installers, 2500 users running as local admin, etc. Since then, I've taken it upon myself to fix every single one of those issues, and they are fixed. Business is happy, other techs are happy, great.

None of that gives me the same sense of accomplishment as today, when I got my first git repo to pass PSScriptAnalyzer rules, run Pester tests, and deploy to a centralized script location.

The rest of my department just uses my scripts - there's not much drive for understanding, but I needed an audience for my accomplishment.

Thanks for being a great resource, everyone.

192 Upvotes

30 comments sorted by

24

u/admiralspark Apr 25 '19

OP, you should write a blog post about this. A lot of sysadmins could benefit from knowing how to deploy from git versioning, how to use Pester as a sysadmin, and how to run the psscriptanalyzer tests.

9

u/spoonstar Apr 25 '19

I'll consider it - I've messed around with Jekyll a little before, so I think the bulk of the work would just be writing it out.

5

u/EachDayGrownWiser Apr 26 '19

I just started a new job a month ago and i’m slowly becoming the scripting guy. So far i’ve made installers with tricks and configuration bits and such, but I would love to learn all of this!

3

u/nascentt Apr 26 '19

Teach us dear leader!

7

u/ypwu Apr 25 '19

Second that, would be interested myself.

2

u/DaNPrS Apr 26 '19

Been using PS for ~2 years. This is the first time I hear of Pester.

Just watched a 30 min YT video on it and I have no idea what's going on lol

Does it push code out from a git and then test if it's present?

3

u/admiralspark Apr 26 '19

If you're familiar with any of the testing suites like Jenkins or Gitlab's built-in tests, it's just a powershell-popular suite in the same style.

People teach classes on this stuff and I'm on mobile, so sorry for not explaining it more than this: when you commit code to a repository, say a testing branch, pester runs tests against the code. It can test for all sorts of stuff--bad code, endless loops, broken connections with remote-pssession use, etc. You can codify it to run tests in the shell against your repo, or you can have something spin up a minimal powershell container and run your scripts there for testing--its all up to how much time and effort you put into it.

Pester is nice, but I always recommend people install gitlab and learn that whole ci/cd pipeline first if they really wanna do this kind of development. It's all nicely packaged in gitlab so the barrier to entry is lower.

3

u/[deleted] Apr 26 '19

Others can describe what testing is. I'll just give you a very real example of why you would want to have automated tests:

I've set up a local repository on my workplace for modules.

One day I added a new cmdlet to the module I have on my local computer, published it to the repository. PowerShell handles version control and packaging, I just increment the manifest version number.

The same day colleagues complain that a command they've used before stopped working and the error doesn't make much sense.

Well, it turns out when I was refactoring a variable in the new function, vscode also changed the string value of an xml namespace in a completely different and unrelated function. I wasn't paying attention to this code - I was only manually testing the new code I was adding.

If I had been a bit more diligent early on, set up some proper testing with pester I could've just executed all the tests on the entire module and caught the bug before I published.

This was just a quick example of how automated testing would avoid the most stupid kind of bug, as a sort of poor-man's quality assurance.

Testing can go way beyond this, to ensure cmdlets not only provide functionality but also to verify that they behave the way you want them to in case of errors and wrong user inputs.

23

u/vornamemitd Apr 25 '19

It‘s always good to see that there still are positive sysadmins out there! Don‘t lose your curiosity and keep up the good stuff :)

15

u/spoonstar Apr 25 '19

The workplace may burn me out, but the job never will!

7

u/Bryan2009 Apr 25 '19

Man for a second there I thought you were in my head. For when I started my position the company was in the same place. I've managed to clean up the GPOs and update servers. For the most part I have MDT/WDS working and being able to image a machine with a base image. Would like to automate a lot more with powershell (or anything really). So I applaud for getting so much done and still have a thirst for everything.

5

u/spoonstar Apr 25 '19

MDT is a beast to get going 'the way you want it'. Having chocolatey around helped me out a lot.

2

u/spoonstar Apr 25 '19

Huge thanks to /u/ramblingcookiemonste for PSDeploy. We have 10 internal chocolatey servers, and you're about to make my job a whole lot easier.

2

u/hollyw00d153 Apr 25 '19

Keep it up and stay thirsty!

2

u/Lagahan Apr 25 '19

I didn't know about pester tests! My scripts are about to get a shakedown 👀

2

u/spoonstar Apr 25 '19

Yours and mine both - Pester does a great job of making you re-evaluate your scripts and ensure it does what you think it does.

2

u/[deleted] Apr 26 '19

Congrats.. Do you have advise on how to start or what to learn first?

2

u/spoonstar Apr 26 '19

It really depends on the issues you have at work. This is essentially how I approached it as time went on.

  • What am I doing repeatedly?

  • Can I do this in a shell vs the UI?

  • Can I do this to more than one computer at a time?

  • Can I effectively give the rest of my staff the same tools?

  • Can I make the computers fix it before our users even notice?

  • Can I give the tools to them as soon as it works so I don't forget?

Depending on where you're at, moving from one of those to another can take time, and that's okay. I was content at the second to last one for two years.

Use the resources that this sub always offers. The In a Month of Lunches books are great, as are the blogs of a few members here.

1

u/[deleted] Apr 26 '19

When I first came as a technician/It Support if you will, I encountered the same problems you had like some users have administrator access.. All websites can visited.. No documentations and no process to start to follow.. I think my first step is to start documenting stuff..

4

u/[deleted] Apr 25 '19

You cannot see it but I am clapping for you. Ever since I started using PS it's changed my life

1

u/RandomSkratch Apr 25 '19

My biggest question is how did you manage to remove local admin access from 2500 users unscathed!?

5

u/spoonstar Apr 26 '19

Honestly, it was a lot of prep work, but it was smooth once it got started.

I had an isolated (by group policy) VM with most of the applications our organization uses on it that had the 'no admin' GPO and I spent a month on that before I even broached the topic. We use have self-service for approved, packaged applications via Chocolatey, so the major potential complaint was nullified.

Once I was satisfied it could work, we increased the scope of 'removed access' to the IT department alone for a month, then spent a week per building or department. Every application that had an issue that could be solved via NTFS/registry permissions was tracked, and by the 4th or 5th staged rollout, we were essentially done but we kept to the process.

3

u/RandomSkratch Apr 26 '19

That's pretty awesome. Can you link to the resources you used for self service approved apps via chocolaty? Or do you mean you set up a local chocolaty repo that contained approved apps and users could install them if they wanted to? If that's the case did they use a GUI or are your users CLI junkies?

2

u/spoonstar Apr 26 '19

or are your users CLI junkies?

Oh, no. No, no, no.

We have a Chocolatey for Business license, which - among other features - has the background agent service that works in conjunction with ChocolateyGUI that is deployed to all user workstations.

We have a few private repos. They're all clones of each other, but they are physically distributed so both the verified updates we pull from the community repositories and the ones we've created for internal apps can be grabbed quickly from our various sites.

3

u/RandomSkratch Apr 26 '19

That's pretty slick. Awesome job! Not all hero's wear capes!

0

u/[deleted] Apr 25 '19

[deleted]

2

u/spoonstar Apr 25 '19

I'll think about it! Impostor syndrome is real.