Import-Module in PowerShell: Load Modules Step by Step

Import-Module in PowerShell loading a custom InventoryTools module

Dana Reyes runs IT for Saguaro Family Clinics in Phoenix, and she keeps her laptop inventory scripts in one small module. Import-Module loads a PowerShell module into your current session, by name or by path: In this tutorial, I’ll build Dana’s InventoryTools module from scratch and use Import-Module in PowerShell to load it, reload it, … Read more

Join-Path in PowerShell: Combine File and Folder Paths

Join-Path in PowerShell combining a folder path with several child segments

Need a folder or file path built inside a script without fighting backslashes? Use Join-Path in PowerShell. Join-Path -Path ‘C:\Finance\Reports’ -ChildPath ‘Denver’ returns C:\Finance\Reports\Denver, with exactly one separator between the parts. I use it in a month-end job for a Denver accounting firm, where plain string concatenation kept giving me doubled or missing backslashes. In … Read more

How to Exit a PowerShell Script (exit, return, break)

PowerShell 7 console showing a script that stops with exit 2 and the $LASTEXITCODE value

To exit a PowerShell script, use the exit keyword, optionally with an exit code such as exit 2. The script stops on that line, and the caller reads the number from $LASTEXITCODE. Here’s Check-Backup.ps1: Without a Backups folder, it stops early: Output: In this tutorial, I’ll show you how to exit a PowerShell script with … Read more

Run a PowerShell Script on a Remote Computer (Invoke-Command)

Invoke-Command PowerShell parameters checked in PowerShell 7

To run a PowerShell script on a remote computer, use Invoke-Command with -ComputerName and either a scriptblock or -FilePath. This one line sends a local .ps1 file to a sales PC and runs it there: In this tutorial, I’ll show you how Invoke-Command in PowerShell works with one or many computers, how to pass local … Read more

How to List Scheduled Tasks with PowerShell

List scheduled tasks with PowerShell

To list scheduled tasks with PowerShell, run Get-ScheduledTask. It returns every task you have permission to see, with its folder, name and state: On a typical PC that’s a couple of hundred tasks. Below I narrow the list by folder, name and state, read run results, see what each task runs, query remote PCs and … Read more

PowerShell: Get the Current Logged-On User on a Remote Computer

Get the current logged-on user on a remote computer with PowerShell

To get the current logged-on user on a remote computer with PowerShell, read the UserName property of Win32_ComputerSystem with Get-CimInstance: It returns DOMAIN\user for whoever is signed in at the console. Below I test the same queries on my own PC, show the two remoting errors you’ll most likely hit, and cover Remote Desktop sessions … Read more

How to Create a PowerShell Module (Step by Step)

Create a PowerShell module with a .psm1 file and a manifest

To create a PowerShell module, save your functions in a .psm1 file inside a folder with the same name, then load it with Import-Module. That’s the whole minimum: Below I build a small real module step by step: export rules, a manifest, a Public/Private layout, the right install folder and auto-loading. I ran each step … Read more

How to Create a Password-Protected Zip File Using PowerShell

Create a password-protected zip file using PowerShell and 7-Zip

PowerShell’s own zip cmdlet can’t add a password, so to create a password-protected zip file using PowerShell you hand the job to 7-Zip. The shortest safe version uses the 7Zip4Powershell module and asks for the password instead of storing it: I tested every step below in PowerShell 7.6 and Windows PowerShell 5.1 with 7-Zip 24.05, … Read more

How to Zip a Folder in PowerShell (Compress-Archive Examples)

How to zip a folder with PowerShell Compress-Archive

If you need to zip a folder in PowerShell, run Compress-Archive with the folder in -Path and the new zip file in -DestinationPath: Compress-Archive -Path .\Q3-2026 -DestinationPath .\Archives\Q3-2026.zip. It’s built in, so there’s nothing to install. Where people get stuck is what lands inside the zip. One asterisk decides whether the folder itself is in … Read more

How to Find SQL Server Instances Using PowerShell (Local, Network, Remote)

Find SQL Server instances using PowerShell

To find SQL Server instances using PowerShell on a server, read the Instance Names\SQL registry key. Every installed instance has a value there, named after the instance: To search a whole network instead, you’ll need Windows PowerShell 5.1 or the SQL tools. Below I cover the registry, services, the network search and remote servers, with … Read more