How to Use 7-Zip from the Command Line in PowerShell

Using the 7-Zip command line (7z.exe) in PowerShell

If you need a password on a zip file, Compress-Archive can’t add one, but 7-Zip can. To use the 7-Zip command line in PowerShell, call 7z.exe by its full path with the & operator: In this tutorial, I’ll walk you through the 7-Zip command line from PowerShell: archives, passwords, exit codes and the quoting traps … Read more

Convert Bytes to KB, MB, GB and TB in PowerShell

PowerShell Get-ChildItem showing file sizes converted from bytes to KB and MB

To convert bytes to KB, MB or GB in PowerShell, divide the number by the built-in literal 1KB, 1MB or 1GB. Here’s 5,368,709,120 bytes in gigabytes: Output: In this tutorial, I’ll show you how to convert bytes to KB, MB, GB and TB, round the result, pick the best unit and convert back, tested in … Read more

How to Unzip Files with PowerShell (Expand-Archive)

How to unzip files with PowerShell Expand-Archive

Every Friday, the Portland, Seattle and Boise stores of Cascade Outdoor Supply email Tom Baker a zip of their weekly reports. To unzip a file in PowerShell, run Expand-Archive with the zip’s path and a destination folder: In this tutorial, I’ll turn that one line into Tom’s weekly script and cover each PowerShell unzip file … Read more

How to Run a PowerShell Script as Administrator

How to run a PowerShell script as administrator on Windows

Your script restarts a service or edits a protected folder, and it stops with “Access is denied.” You’re signed in as an admin, yet the script still doesn’t have admin rights. Quick answer: to run a PowerShell script as administrator, open PowerShell with Run as administrator and run the script there, or start an elevated … Read more

PowerShell Script File Extensions (.ps1, .psm1, .psd1) Explained

PowerShell script file extensions .ps1, .psm1 and .psd1 explained

The PowerShell script file extension is .ps1. Save your code in a plain-text file that ends in .ps1, then run it from its folder with .\ in front of the name: Output: In this tutorial, I’ll explain each PowerShell script file extension you’ll run into, from .ps1 and .psm1 to .psd1, .ps1xml and .cdxml. I … Read more

How to Call a PowerShell Script from Another Script

Call a PowerShell script from another script with the call operator

If you have a main script that needs to run a helper script, put the call operator and the helper’s full path on one line: & “$PSScriptRoot\Jobs\Get-OpenInvoices.ps1”. That’s how you call a PowerShell script from another script. The line itself is easy. The trouble starts around it: relative paths that break when you launch from … Read more

How to Create a PowerShell Script Step by Step

How to create a PowerShell script step by step

Dana Reyes, who runs the office at Harbor Point Logistics in Seattle, kept asking how full the shared Reports folder was. Here’s how to create a PowerShell script for that: type the commands in a text editor and save them with a .ps1 extension: In this tutorial, I’ll show you how to create a PowerShell … Read more

How to Run a PowerShell Script (.ps1) on Windows

How to run a PowerShell script (.ps1) on Windows

By default, double-clicking a .ps1 file opens it in Notepad instead of running it. To run a PowerShell script, open PowerShell in the script’s folder and type its name with .\ in front: In this tutorial, I’ll show you how to run a PowerShell script from the console, Command Prompt, the Run dialog and File … Read more

Self-Service Password Reset with PowerShell: SSPR Reports

Self-service password reset with PowerShell

To manage self-service password reset (SSPR) with PowerShell, use Microsoft Graph to see who is enabled and registered. The registration report shows, for every user, whether they can reset their own password: SSPR itself is turned on in the Microsoft Entra admin center. PowerShell’s job is reporting and follow-up, so you can find the people … Read more

How to Convert PDF to CSV Using PowerShell

Convert PDF to CSV with PowerShell

To convert a PDF to CSV with PowerShell, first extract the PDF’s text with a text extraction tool, then parse the lines into objects and save them with Export-Csv. PowerShell can’t read PDF text on its own: The extraction is one command. Turning the text into clean rows is where the real work is, and … Read more