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 Convert PDF to Word Using PowerShell (Word COM)

Convert PDF to Word with PowerShell

PowerShell can’t convert PDF to Word by itself, but desktop Microsoft Word can, and PowerShell drives Word through COM. Open the PDF in a hidden Word instance and save it as .docx: Word rebuilds the PDF as an editable document, and 16 is the .docx format code. Below you’ll find the full script, a folder … Read more

How to Convert JPG to PDF Using PowerShell (No Extra Software)

Convert JPG to PDF with PowerShell

To convert a JPG to PDF with PowerShell, print the image to the built-in Microsoft Print to PDF printer with PrintToFile turned on. The PDF lands at the path you give, with no Save As dialog and nothing to install: Below I build that into a reusable function, then convert one photo, combine several receipts … Read more

How to Convert PNG to JPG Using PowerShell

Convert PNG to JPG using PowerShell

To convert PNG to JPG with PowerShell, load the image with System.Drawing and save it in JPEG format. It’s built into Windows, so you don’t need to install anything: That works, but transparent areas turn black and you can’t set the quality. Below I fix both with a reusable function, compare quality settings and convert … Read more

How to Check Password Expiration Date in PowerShell

Check password expiration date in PowerShell

To check a password expiration date in Active Directory with PowerShell, read the computed msDS-UserPasswordExpiryTimeComputed attribute and convert it to a date: Below I cover the attribute and the math behind it, an expiring-soon report, Microsoft 365 users, and local accounts. My test PC isn’t on a domain, so I ran the date math and … Read more

How to Convert HEIC to JPG Using PowerShell (No Third-Party Tools)

Convert HEIC to JPG using PowerShell

To convert HEIC to JPG using PowerShell, decode the photo with the Windows imaging decoder and save it with JpegBitmapEncoder. With the function from this page, it’s one line per photo or folder: It needs Microsoft’s free HEIF Image Extensions from the Microsoft Store. I tested it in PowerShell 7 and Windows PowerShell 5.1 on … Read more

Measure-Object in PowerShell: Sum, Average, Max and Count

Measure-Object in PowerShell

Measure-Object calculates the count, sum, average, maximum and minimum of numbers or of a property. Pipe the values to it and pick the statistics you want: Output in Windows PowerShell 5.1: PowerShell 7 shows the same numbers plus an empty StandardDeviation row. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1 and note … Read more

How to Enable PowerShell Logging (Script Block and Module)

Enable PowerShell logging

To enable PowerShell logging, turn on Script Block Logging, which records the code of every script and command that runs. For Windows PowerShell 5.1, set this registry value as administrator: PowerShell 7 uses its own key and log. Below I check what’s already on, explain the three kinds of logging and show how to enable … Read more

PowerShell Sort-Object: Sort by Property, Number, Date and More

PowerShell Sort-Object examples sorting CSV rows as numbers

PowerShell Sort-Object puts objects in order by one or more property values. Pipe the objects in, name the property, and add -Descending if you want the largest values first: In this tutorial, I’ll show you how to use PowerShell Sort-Object with properties, numbers stored as text, dates, -Unique, -Top and hash tables. Every example below … Read more