How to Convert HTML to PDF in PowerShell (Edge, Chrome or Word)

Convert HTML to PDF in PowerShell

To convert HTML to PDF in PowerShell, let Microsoft Edge do the rendering. Edge ships with Windows 10 and 11, and its headless mode prints any HTML file to a PDF without opening a window: PowerShell has no built-in PDF cmdlet, so a browser engine is the most reliable route. Below I build that line … Read more

How to Convert JSON to CSV in PowerShell (Nested JSON Too)

Convert JSON to CSV in PowerShell

To convert JSON to CSV in PowerShell, read the file as one string, turn it into objects with ConvertFrom-Json, and save them with Export-Csv: That works for flat JSON. Nested objects, dates and records with different fields need a little more, so I tested each case in PowerShell 7 and Windows PowerShell 5.1. Convert a … Read more

How to Convert a String to a Hashtable in PowerShell (and Back)

Convert a string to a hashtable in PowerShell

To convert a string to a hashtable in PowerShell, use ConvertFrom-StringData. It reads text with one key=value pair per line and returns a hashtable: Output: Below I handle one-line strings, backslashes, JSON and value types, then go the other way and turn a hashtable back into a string. Every example ran in PowerShell 7.6 and … Read more

PowerShell foreach File in a Folder (With Examples)

PowerShell foreach file in a folder

To loop through each file in a folder in PowerShell, get the files with Get-ChildItem -File and process them in a foreach loop: Each $file is a full file object with Name, Length, LastWriteTime and more. Below I use a sample Invoices folder to show the pipeline version, filtering, subfolders, counters, renaming and parallel processing. … Read more

How to Count Files in a Folder Using PowerShell

Count files in a folder using PowerShell

To count files in a folder using PowerShell, get only the files with Get-ChildItem -File and read the Count property. Add -Recurse to include every subfolder: That’s the short answer. The count can still be wrong, though: hidden files are skipped, -Filter behaves differently in Windows PowerShell 5.1, and -Exclude doesn’t skip folders. I ran … 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

How to Get the Outlook Inbox Item Count Using PowerShell

Get the Outlook inbox item count using PowerShell

To get the Outlook inbox item count with PowerShell on a PC with classic Outlook, open the inbox through Outlook’s COM object and read Items.Count. Folder 6 is the inbox: For Microsoft 365 mailboxes, Microsoft Graph and Exchange Online give the same numbers without Outlook running. Below I cover all three, then build a subfolder … Read more

How to Convert Excel to PDF Using PowerShell

Convert Excel to PDF with PowerShell

To convert Excel to PDF with PowerShell, open the workbook through Excel’s COM object and call ExportAsFixedFormat with type 0, which means PDF: This needs Excel installed on the PC. Below I wrap it in a function that always closes Excel, export a single sheet, fit wide sheets on one page and convert a folder. … Read more

How to Convert WebP to JPG Using PowerShell

Convert WebP to JPG using PowerShell

To convert WebP to JPG with PowerShell, decode the WebP with Windows’ built-in image codecs through WPF’s BitmapDecoder, then save the pixels as a JPEG. System.Drawing, the usual choice for images, can’t read WebP at all: Below I show why System.Drawing fails, check that the WebP decoder is there, fix the black background on transparent … Read more