$PSScriptRoot & %~dp0: Script's Home

When writing portable scripts, one of the first challenges is locating files relative to the script itself. Whether in PowerShell or a classic Batch file, I need a reliable way to find my script’s “home” directory. This guide breaks down the two most important tools I use for this job: $PSScriptRoot for PowerShell and %~dp0 for Batch. 1. The Batch Method cd /d %~dp0 In Windows Batch scripting (.bat, .cmd), the magic variable %~dp0 is the standard for getting the script’s directory. I often use it with cd to change the working directory. ...

November 12, 2025 · The PwshTips Team

PowerShell: Working with Objects

What truly sets PowerShell apart from traditional command-line shells like Bash or Zsh is its foundational design: it’s built around objects, not text. While other shells pass streams of text between commands, PowerShell passes rich, structured objects. This fundamental difference is PowerShell’s superpower, making it an incredibly efficient and robust tool for automation, data processing, and system administration. This guide explores what it means to work with objects and how I leverage the object-oriented pipeline to write cleaner, more powerful, and more reliable scripts. ...

October 27, 2025 · The PwshTips Team

PowerShell: New Operators (&&, ||, ??, ?:)

PowerShell has evolved significantly over the years, and with the release of PowerShell 7, it introduced several modern operators that make scripting more efficient, readable, and aligned with other popular programming languages like C# and JavaScript. This guide provides a deep dive into these new operators, showing how I use them to simplify my code and make my scripts more robust. The key operators I’ll cover are: && and || — Pipeline chain operators ?? and ??= — Null-coalescing operators ?: — Ternary operator 1. Conditional Execution: The Pipeline Chain Operators (&& and ||) Introduced: PowerShell 7.0 ...

October 24, 2025 · The PwshTips Team