Building a PowerShell Toolkit for Everyday Administration

If You Have to Do It More Than Once, Automate It

Jon Sexton
5 min readSep 29, 2020
Photo by Caspar Camille Rubin on Unsplash

One common issue I have always had regardless of my position is being persistently swamped with repetitive tasks and never having enough time to focus on what is important. Certainly, information technology is supposed to be fast-paced and I am glad that I am never bored. At the same time, being overwhelmed by menial tasks is a path to burnout.

It is a challenging problem because menial tasks will always exist. No matter how smart you get with password policy, for example, there is always a human element to contend with… No matter how robust your computer image is, you will always need to make additions as the needs of your workers change. There are a whole host of other situations that you will never be able to eliminate but there is a lot you can do to simplify their handling. Enter PowerShell.

The Value of PowerShell in System Administration

PowerShell is deeply engrained in Windows and is practically a one-stop-shop for just about any administrative task you can think of. Not only can it save you time on repetitive tasks but it can ensure that you perform tasks consistently and without error. Besides, when you need a break from the daily grind, it is a rewarding — dare I say “fun”? — way to take a break from the mundane and unleash your creativity.

One cool thing I have done with PowerShell recently is to build a toolkit for everyday administrative tasks. With this toolkit, I can quickly connect to any machine with Windows Remote Management enabled, launch any of my preset scripts, walk away and check in later to confirm that the task is completed. (I will later provide a blueprint for you to quickly implement this too.) Here are some of the items this includes:

  • Add-Fonts.ps1 — installs selected fonts on the remote computer
  • Change-TPMPin.ps1 — changes the TPM pin on the remote computer that has Bitlocker enabled on it
  • Install-MicrosoftProject.ps1 — I have a script like this for automatically installing any program that is not part of my base image
  • Restart-Computer.ps1 — simply restarts a remote computer
  • Retire-Computer.ps1 — removes a retired computer from the domain
  • Windows-Repair.ps1 — runs DISM and SFC on a remote computer to automate the repair of the OS

I have many more scripts that I use to automate my daily work but the truth is that not all the scripts save me a lot of time on their own. What truly makes my use of scripts transformative is my script “Invoke-Remote.ps1.” With this script, I can accomplish the following things:

  • Quickly select a remote computer
  • Automatically connect to the remote computer
  • Select from a preset list of scripts to run on the remote computer
  • Automatically run the selected script on the chosen computer
  • Provide feedback to the user on the success or failure of the script
  • Save time, footwork, and effort
  • Make you look like a stone-cold wizard
  • Make you feel like a certified bad-ass

If you aren’t interested in looking like a stone-cold wizard, I will provide a real-world example to demonstrate the value this could have for you.

Using a Powershell Toolkit in Practice

One common request I get, which would typically be somewhat of a challenge, is installing an ad hoc piece of software like Microsoft Project on a user’s computer.

It is reasonably easy to double-click the executable file and click through a few screens to complete this process. In practice, it can be hard, however, to get the user to commit to a time when you can actually take possession of their laptop, complete the work, and get their confirmation everything works as expected.

Here is how it would work, with heads-up to the user, using my toolkit:

  1. Launch PowerShell as administrator
  2. Navigate to C:\Powershell
  3. Enter .\Invoke-Remote.ps1 (this is a signed script so there is no need to set the execution policy)
  4. Enter Install-MicrosoftProject.ps1, which is also listed by Invoke-Remote.ps1
  5. Enter [Computer Name] (usually in a predefined format)
  6. Wait for the process to complete and the script advises the user to reboot

Sounds pretty simple, huh? Well, there was some substantial planning, experimentation, effort, and testing put into this. But, it really does feel amazing when a task that used to take 30 minutes in practice now takes about 30 seconds. What’s even better is that the user is typically more satisfied with this process and you can free up vast amounts of time for doing things that are more important to you.

Want to know how you can implement this too? Below is the basic “recipe” for putting together your own toolkit.

Implementing a PowerShell Toolkit

Prerequisites

  • Windows Remote Management must be enabled on target machines
  • For a program like Microsoft Project to be installed without prompts (“silently”), you must put a custom configurations.xml file in the executable’s directory

Instructions

  1. Create a toolkit directory, in a place of your choosing, where you can store your PowerShell Scripts and your version of Invoke-Remote.ps1
  2. Decide how you want to handle your execution policy: You can sign your scripts so they can be automatically run or temporarily bypass a strict execution policy whenever you run a script — this step assumes some knowledge of PowerShell
  3. Create the scripts for your toolkit and save them in your toolkit directory
  4. Create the Invoke-Remote.ps1 script that will run these scripts using this basic logic:

#Change directory and list scripts

cd “C:\PowerShell”

Write-Host “See available scripts below”

dir | Format-Table -Property Name

#Prompt user for a script they would like to run and set to variable

$selectScript = Read-Host -Prompt “Enter name of the above script you wish to run”

#Set remote computer variable from user input

$remoteComputer = Read-Host -Prompt “Enter Computer Name in format ‘WS-XXXXX’”

#Run the selected script on the remote computer remotely

Function Invoke-Remote ()

{

Invoke-Command $selectScript -ComputerName $remoteComputer -Credential [domain]\administrator

}

Invoke-Remote

Summing It Up

The process of creating a PowerShell toolkit to automate daily processes is a valuable experience that will save you time, footwork and effort. It is something that can be fun but will also pay dividends in the future if you take the time to do it.

I personally have enhanced the consistency and quality of my work by implementing a toolkit. I also have more time to focus on the things that are most important to me and my organization.

Want the skinny on other valuable problem solving techniques learned over years of experience? Read What 7 Years as “The IT Guy” Taught Me About Problem Solving.

--

--

Jon Sexton

Starting off providing tech support in call centers , I have worked my way up to IT Administrator for my county. In the process I have accumulated many stories.