Tips and Tricks

Tips and Tricks
Aaron Jensen
PowerShell for Admins

Tips for Writing Cross-Platform PowerShell Code

I just spent a month updating one of our PowerShell modules to support Linux and MacOS. I learned a lot that I wanted to share with the community as cross-platform support becomes more and more important. Use “Environment” Class Properties Instead of “env:” Drive Environment variables are different between the different operating systems. All of them have PATH , but not much else. Windows and MacOS both have variables for the temp directory, but they have different names.

Eli Hess
PowerShell for Admins

Executing LINQ Queries in PowerShell – Part 2

And we’re back! Ok, so in the last blog we began a conversation about delegates and using LINQ in PowerShell. In today’s post, I’m going to give an example of how it can be incredibly useful. Let’s talk about Joins. Joins In my line of work, I’m constantly running into the need to combine datasets from multiple sources that relate to each other and pull out some specific properties. Say you have two internal services, one which is used to track production status and another which is used to monitor whether machines are online.

Eli Hess
PowerShell for Admins

Executing LINQ Queries in PowerShell – Part 1

Greetings PowerShellers! Lately, I’ve been itching to write something up on Microsoft’s Language-Integrated Query (LINQ). You’ve likely encountered it if you’ve done any development in C#. LINQ is an incredibly powerful querying tool for performing look-ups, joins, ordering, and other common tasks on large data sets. We have a few similar cmdlets built into PowerShell, but other than the ‘.Where()’ method on collection objects nothing that comes close to the speed at which LINQ operates.

msorens
PowerShell for Admins

Do Anything in One Line of PowerShell

PowerShell provides a tremendous boon to productivity for computer professionals of all types. But, you have to admit: it can be a bit daunting to get up to speed! Indeed, as someone who has a fair amount of experience using it, I still find myself having to look up how to do things–frequently. So I started keeping track of the recipes I was using the most. And came up with a list of 400 or so, published in 4 parts.

msorens
PowerShell for Admins

PowerShell Gotchas

You can certainly find a number of articles around that present PowerShell pitfalls that can easily trip you up if you are not careful. I took a different approach in my three-part series, A Plethora of PowerShell Pitfalls. The first two parts are presented in quiz format, together covering the top 10 “gotchas”. They will help you test your awareness to see if you even realized the danger and did not know you’ve been skirting those traps for awhile.

msorens
PowerShell for Admins

Pitfalls of the Pipeline

Pipelining is an important concept in PowerShell. Though the idea did not originate with PowerShell (you can find it used decades earlier in Unix, for example), PowerShell does provide the unique advantage of being able to pipeline not just text, but first-class .NET objects. Pipelining has several advantages: It helps to conserve memory resources. Say you want to modify text in a huge file. Without a pipeline you might read the huge file into memory, modify the appropriate lines, and write the file back out to disk.

Duffney
PowerShell for Admins

A Practical Guide for Using Regex in PowerShell

Regular Expressions is often referred to as wizardry or magic and for that reason I stayed away from it for most of my career. I used it only when I had to and most of the time just reused examples that I found online. There’s nothing wrong with that of course, but I never took the time to learn it. I thought it was reserved for the elite. Turns out that it’s not that complicated and that I had been using it for years without knowing it.

Matthew Hodgkins
Tips and Tricks

Ultimate PowerShell Prompt Customization and Git Setup Guide

Do you spend hours a day in PowerShell? Switching back and forth between PowerShell windows getting you down? Have you ever wanted “Quake” mode for your terminal? If we are going to spend so much time in PowerShell, we may as well make it pretty. Check out the Ultimate PowerShell Prompt Customization and Git Setup Guide for how to: Install and customize ConEmu Enable Quake Mode for your terminal Setup your PowerShell Profile Install and use Posh-Git Generate and use SSH Keys with GitHub Squash Git commits

msorens
PowerShell for Admins

Create Custom Monitors with PowerShell

Sometimes, as a developer, you want to be be able to keep track of free space on a drive, the size of a log, the load on your CPU, the number of users logged in, etc. With PowerShell, it is typically just a matter of finding the right cmdlet amidst the large (and rapidly growing) pool of cmdlets provided by Microsoft and by third parties. Then you just run Get-Foo to check details about the foo resource.

Graham Beer
PowerShell for Admins

A date with PowerShell

At the beginning of July, we welcomed our 3rd son into the world. As days past my wife and I would say, “wow, he’s 11 days old. Can you believe it?!”. I’m sure parents out there are relating to this! This gave me an idea for a fun script that would get your age in years, months and days, tell you how many days until your birthday and your star sign.