We system administrators are expected to do more, with less time. We have a packed day and still expected to produce more. We need a way to automate and make our daily tasks more efficient. This is a feeling I’ve had, so I thought I’d share a bit about the journey I’ve had to effectivize, not only my daily tasks but lots of small repetitive tasks.
We all know PowerShell, right? It is this scripting language that has been with us since 2006. PowerShell is a neat tool for us to perform command-line tasks, a powerful scripting language and configuration management framework. As a sysadmin you probably have Windows Servers in your stack. I my opinion you’ll need to learn PowerShell.
Personally I find PoweShell helpful to automate my daily tasks. My work has become easier because of PowerShell. A bonus is getting a look under the hood of services and configurations with CLI, not often you experience that with GUI…
PowerShell aside, we’re taking a look at Visual Studio Code today. As PowerShell has made taks more efficient, VS Code is making writing PowerShell more efficient. Let us take a look, shall we?
1. Install VS Code
Firstly we need to install VS Code
- Go to aka.ms/vscode and download the current release
- It is pretty much a “Next, Next, Install” installation.
2. Create a Github repository
Github or any other Git repository is great to have as it has capabilities ment for writing code. Git tracks the changes you make to files, version control of files and revert capabilities. Git also makes collaboration easier, allowing changes by multiple users to be merged into one source.
2.1 Create an account
Go to Join GitHub · GitHub to register an account
2.2 Create a repository
Click “Create respositry” and fill in a repository name. I chose the fabilous name cuddly-goggles!
Now that we have a Github repository, we need a way to access the repository from VS Code. You guessed it, we need Git!
2.3 Download and configure Git
To start using our Github repository with VS Code, we need the application Git.
Download Git from this link: Git – Downloads (git-scm.com) and select your desired download. Git can also be installed with winget by running the following command:
winget install --id Git.Git -e --source winget
The installation of Git is pretty much a “Next, Next, Finish” as well, but with a minor change.
When the Choosing the default editor used by Git comes, I like to change that to Visual Studio Code.
2.4 Clone repository
Open up VS Code again and press the Source Control pane on the left hand side. From the Command Palette choose Github. Press Allow.
This opens up a browser with an authorization page. Press the button Authorize Visual-Studio-Code
When VS Code opens back up, choose the newly created repository from the Command Palette. Select a location of your computer you’d like to clone the repository to.
There you go! A Github repository directly in VS Code.
3. Visual Studo Code Extensions
To further enhance our great experience with VS Code, we can add extensions. I’ll talk a bit out a few extensions I love to use, that both increases productivity as well as functionallity.
This may be implied, but we’ll need a PowerShell extension to run our PowerShell code. We’ll first need to add the PowerShell extension into VS Code, then install PowerShell 7.
Installing the VS Code PowerShell extension is pretty straight forward:
After installing the extension, install PowerShell version 7 from the following link: aka.ms/install-powershell
Once installed, restart VS Code. Now you have the full PowerShell experience you get with ISE, but with a much better IDE. You get great functions like:
- IntelliSense – context-aware code completion
- Integration with Git is seamless
- Code folding
- Powerful keyboard shortcuts
It happens often, you have to share a bit of code with a colleague. Now that you have Git, sharing and collaboration is easy. But if you’d like to get a colleague to take a quick peak at a function?
CodeSnap is a function that makes screenshotting code easy. Lets say I want to share a function real quick with you
Beautiful screenshot, right? This is produced by CodeSnap. Be aware, some colleagues might be irritated by recieving code as screenshot 😬
3.3 Better Comments
Writing readable code is a necessity. Both for yourself and others trying to understand your code. Better Comments helps you make human-friendly comments in your code. The extension lets you categorize your annnotations into the following categories:
As well as the predefined annotations, you can create custom annotations to your liking.
3.4 Random Everything
Have you ever been in the situation where you need to create dummy data? You should never test your code against production data as the scripts may not function as intended. Good thing we’ve got an extension to create random dummy data!