pwsh Start-Job and Wait-Job

PowerShell’s Start-Job is a powerful tool for running commands and scripts asynchronously as background processes. However, its behavior, especially when combined with Wait-Job and -Credential, often leads to confusion. This post demystifies how Start-Job works, why some installers fail silently inside jobs, and how to properly manage background tasks in PowerShell. Assigning Start-Job to a Variable: Why It Matters Consider these two commands. They both launch a background job to run a command prompt instruction. ...

November 26, 2025 · The PwshTips Team

$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, you need a reliable way to find your script’s “home” directory. This guide breaks down the two most important tools 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. It’s often used with cd to change the working directory. ...

November 12, 2025 · The PwshTips Team

Credential Elevation in Invoke-Command

Credential Elevation in Invoke-Command – The Full Truth When using PowerShell’s Invoke-Command for remote administration, understanding how credential elevation works is crucial. Many misconceptions exist, especially regarding a non-existent -RunAsAdministrator flag or UAC prompts. This post clarifies the real mechanics behind running commands as an administrator remotely. 🔍 Quick Summary Question Answer Does Invoke-Command have a -RunAsAdministrator flag? ❌ No, this flag does not exist. How does elevation actually work? ✅ Elevation is entirely determined by the -Credential parameter you pass and the nature of the remote process. 1. How Invoke-Command Handles Credentials and Elevation Invoke-Command operates by establishing a remote session (typically via WinRM) using the credentials you provide. The elevation of the commands executed within that session depends directly on the privileges of the user account associated with those credentials. ...

November 12, 2025 · The PwshTips Team

gsudo vs. Invoke-SSHCommand for Admin Tasks

Automating administrative tasks on Windows often requires running scripts with elevated privileges. When you can’t have a UAC prompt interrupting your workflow, you need a reliable, non-interactive way to elevate. Two powerful and modern approaches to this problem are gsudo for local elevation and Invoke-SSHCommand for remote execution. This guide provides a deep dive into both tools, comparing their strengths and weaknesses to help you decide which one is the right fit for your automation needs, whether you’re managing a local machine or a fleet of remote servers. ...

November 10, 2025 · The PwshTips Team

PowerShell Remoting: WinRM vs. SSH

PowerShell is the go-to tool for automating tasks on Windows, and its remoting capabilities are a cornerstone of its power. For years, WinRM (Windows Remote Management) with the Invoke-Command cmdlet has been the standard. However, with the rise of cross-platform development and the native integration of OpenSSH in Windows, a new contender has emerged: Invoke-SSHCommand. Both cmdlets let you run commands on remote machines, but they operate on fundamentally different protocols. Understanding the difference is key to choosing the right tool for your environment. This guide breaks down the pros, cons, and best use cases for each. ...

November 9, 2025 · The PwshTips Team

Non-Interactive Elevation on Windows

Automating tasks that require administrator privileges on Windows presents a common challenge: how do you handle the UAC (User Account Control) prompt in a non-interactive script, such as in a CI/CD pipeline or a scheduled task? Attempting to bypass UAC is a major security risk and is not recommended. Instead, you should use tools and methods that are designed for non-interactive elevation. This guide will cover the two best approaches: using the open-source gsudo tool for scripted elevation and the built-in Windows Task Scheduler. ...

November 8, 2025 · The PwshTips Team

Remote Admin: WinRM vs. SSH for Elevated Tasks

When you need to run a command as an administrator on a remote Windows machine, you have two primary technologies to choose from: the traditional WinRM (Windows Remote Management) and the modern, cross-platform OpenSSH. Both can get the job done, but they handle elevation and authentication in fundamentally different ways. This guide will provide a deep dive into both methods, comparing their strengths, weaknesses, and best use cases to help you choose the right tool for your remote administration needs. ...

November 8, 2025 · The PwshTips Team

File Transfer Speed: SCP vs. Robocopy vs. Copy-Item

When it comes to transferring large files (10–100 GB) between Windows systems, the tool you choose can have a massive impact on speed, reliability, and security. In this ultimate showdown, we compare three titans of file transfer: the secure and universal SCP (OpenSSH), the multi-threaded powerhouse Robocopy (SMB), and the PowerShell-native Copy-Item (WinRM). We’ll test them across different network conditions, from a high-speed 10 GbE LAN to a real-world 5G wireless connection, to help you decide which tool reigns supreme for your specific needs. ...

November 7, 2025 · The PwshTips Team

SSH vs. WinRM: PowerShell Remoting

In the world of remote administration with PowerShell, two protocols stand out: the traditional, Windows-native WinRM (Windows Remote Management) and the modern, cross-platform SSH (Secure Shell). Both allow you to execute commands on remote machines, but they are built on fundamentally different technologies and philosophies. Choosing the right protocol is crucial for building a secure, efficient, and scalable automation strategy. This guide will provide a deep dive into both SSH and WinRM, comparing their setup, security, performance, and best use cases to help you make an informed decision. ...

November 6, 2025 · The PwshTips Team

Automate Office 2021 Install & Remove Old Versions

When deploying Microsoft Office 2021, one of the key considerations is how to handle older, existing versions like Office 2010. By default, the modern Office installer will automatically remove these older versions, but for automated or customized deployments, you need more control. This guide will walk you through using the Office Deployment Tool (ODT) to create a silent, automated installation of Office 2021 that also cleanly removes any older Office versions. ...

November 4, 2025 · The PwshTips Team