How to Install a PowerShell Module Offline (.nupkg)

Install a PowerShell module offline from a local folder repository with Install-Module

To install a PowerShell module offline, download it on a PC with internet, copy the folder to the offline machine, and put it in a module path: Save-Module grabs the module and its dependencies. On the offline side, copy each folder into your Modules folder, or install the .nupkg files from a local repository. Tom … Read more

Fix: Parameter Set Cannot Be Resolved Using the Specified Named Parameters

PowerShell 7 console showing the AmbiguousParameterSet error from six built-in cmdlets

You add one more parameter to a working command, and PowerShell refuses to run it. The error says “Parameter set cannot be resolved using the specified named parameters.” Quick answer: you combined parameters that belong to different parameter sets, so PowerShell can’t pick one. Remove one of them. Here, -Path and -LiteralPath clash: Output: In … Read more

Out-String in PowerShell: Convert Output to Text

Convert PowerShell output to text with Out-String

If you need PowerShell output as plain text for a ticket, an email or a log, Out-String is what you need. It turns any output into exactly the text you’d see on screen: In this tutorial, I’ll show you how PowerShell Out-String works: one string vs -Stream, the trailing newline, -Width, -NoNewline, searching formatted output … Read more

IndexOf in PowerShell: Find a Position in a String or Array

PowerShell IndexOf with StringComparison, culture and ordinal searches in a PowerShell 7 console

PowerShell IndexOf returns the zero-based position of the first match, or -1 when there’s no match. It works on strings and on arrays: In this tutorial, I’ll show PowerShell IndexOf on strings, arrays, lists and objects, with the case and culture traps I hit in PowerShell 7 and 5.1. How does IndexOf work on a … Read more

Empty the Recycle Bin with PowerShell (Clear-RecycleBin)

Clear the Recycle Bin with PowerShell: Clear-RecycleBin -WhatIf previews emptying the bin for all drives or one drive

To clear the Recycle Bin with PowerShell, run Clear-RecycleBin. Add -Force so it doesn’t stop for confirmation, and remember that the files are gone for good: Dana Reyes does IT support for an accounting firm in Seattle. The shared front-desk PCs fill their Recycle Bins with exported reports, and she wants a cleanup she can … Read more

Default Parameter Values in PowerShell

PowerShell 7 console showing a function with a default parameter value and the $PSBoundParameters check

To set a default parameter value in PowerShell, assign it inside the param() block, like [string]$City = ‘Denver’. PowerShell uses that value whenever the caller skips the parameter: Output: In this tutorial, I’ll show you how a default parameter value in PowerShell works in functions and scripts, how to tell whether a value was passed, … Read more

Disable a Windows Service with PowerShell

Disable a service with PowerShell: Get-Service, CIM and sc.exe all report the startup type as Disabled

To disable a service in PowerShell, stop it with Stop-Service and then set its startup type to Disabled with Set-Service, in a PowerShell window opened as administrator: Tom Baker runs IT for a dental office in Denver. The front-desk PCs came with the Xbox services, and he wants them off on every machine, with a … Read more

How to Run a PowerShell Script from a Batch File

How to run a PowerShell script from a batch file in Command Prompt

A coworker wants your PowerShell report, but they live in Command Prompt and just want something to double-click. A small .bat file is the easiest way to hand it over. Quick answer: to run a PowerShell script from a batch file, call powershell.exe (or pwsh.exe for PowerShell 7) with -File and the script path built … Read more

How to Get the Domain Name with PowerShell

Get the domain name with PowerShell using Get-CimInstance Win32_ComputerSystem

To get the domain name with PowerShell, read the Domain property of the Win32_ComputerSystem class. It works the same in PowerShell 7 and Windows PowerShell 5.1: In this tutorial, I’ll show you how to get the domain name in PowerShell, check whether a PC is joined at all, build the full computer name (FQDN) and … Read more

Delete a Scheduled Task with PowerShell

Delete a scheduled task with PowerShell: Unregister-ScheduledTask removes a task from a Task Scheduler folder

To delete a scheduled task with PowerShell, run Unregister-ScheduledTask with the task’s name and folder, and add -Confirm:$false so it doesn’t stop to ask: Here’s the situation I usually face. An old server has a pile of tasks from scripts nobody runs anymore, and I need to remove a handful of them without touching the … Read more