Powershell
PowerShell: because life’s too short for endless mouse clicks. In this category, you’ll find scripts, tips, tricks, lessons learned, and the occasional “what on earth was Microsoft thinking?” moment. From one-liners to full-blown automation adventures, we’ve got your shell covered.
-
Part 1: Understanding PowerShell Profiles — Your Personalized Command-Line Workspace PowerShell is incredibly powerful out of the box, but one of its best features is often overlooked: PowerShell profiles. A PowerShell profile allows you to automatically configure your shell every time it starts. Think of it as a startup script for PowerShell. Instead of repeatedly defining aliases, importing modules, or tweaking your prompt, you can save those customizations in a profile and have them loaded automatically.…
-
Learn how to calculate the maximum depth of a JSON object in PowerShell using a recursive approach. This article explains the logic behind the Get-JsonDepth function, discusses why arbitrary depth limits should be avoided, and explores the balance between accuracy, maintainability, and performance when traversing complex object graphs.
-
PowerShell Remoting over SSH combines the power of PowerShell with the universal availability of SSH. Especially in environments where both Windows and Linux systems are managed, it provides a modern and flexible way of working.
-
Storing credentials in plain text within scripts is a common but risky practice. While it may seem convenient for automation, it exposes sensitive data to anyone with access to the code. In this article, we explore a safer approach using PowerShell’s ConvertTo-SecureString and ConvertFrom-SecureString to encrypt passwords tied to a specific user and machine. This method significantly reduces the risk of credential leaks while keeping automation seamless.
-
When automating tasks on Windows, PowerShell scripts often handle the heavy lifting—but automation isn’t complete until those scripts run on their own. While many admins still use the graphical Task Scheduler, PowerShell provides a full set of cmdlets that make creating, managing, and automating scheduled tasks easier, faster, and more repeatable. In this guide, we’ll walk through how to schedule PowerShell scripts entirely through PowerShell using cmdlets like New-ScheduledTaskAction, New-ScheduledTaskTrigger, and Register-ScheduledTask. We’ll also explore best practices, logging,…
-
Have you ever written a script that worked perfectly in testing, only to cause chaos in production? I have, and it was one of the most stressful days of my career. This experience changed how I write scripts. More checks, fewer assumptions, and no blind trust in defaults.
-
Switch statements in PowerShell are like the Swiss Army knife of control flow – they can handle multiple conditions with the elegance of a ballet dancer and the efficiency of a German engineer. Think of them as the sophisticated cousin of the if-else statement who went to college, learned multiple languages, and now works at a consulting firm. While if-else chains are like asking “Are you this? No? How about this? No? This?” until you…
-
Enums in PowerShell provide a clean way to work with strongly typed values, improving readability, maintainability, and reducing errors. By grouping related constants under a single type, you avoid magic numbers and hardcoded strings, gain autocompletion, and enable built-in validation in functions. Whether you use native syntax, Add-Type with C#, or classes with static properties, enums make your scripts more robust and easier to manage.
-
Dot sourcing is like the PowerShell equivalent of borrowing your neighbor’s tools – except instead of forgetting to return them, you get to keep everything permanently in your workspace. It’s a powerful feature that allows you to run a script in the current scope rather than in a new, child scope, making all its goodies available to you immediately. Think of it as the difference between hiring a contractor who works in their own workshop…
-
Hashtables and PSCustomObjects may look similar in PowerShell, but they serve very different purposes. This post explores their syntax, performance, and practical use cases, helping you choose the right structure for dynamic data handling or clean output formatting.
