How to Convert HTML to JSON in PowerShell

Convert HTML to JSON in PowerShell

To convert HTML to JSON in PowerShell, pull the data out of the HTML into objects first, then pipe the objects to ConvertTo-Json. For a clean table, the quickest way is to cast the HTML to [xml]: Real web pages are rarely clean enough for that. Below I cover the [xml] route, why it breaks … 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

50 PowerShell Interview Questions and Answers (2026)

PowerShell interview questions and answers with tested examples

Most PowerShell interview questions come back to one idea: PowerShell passes .NET objects, not text. If you can show that in two lines, you’ve answered half the screening round already: Output: Get-Item returned a FileInfo object, so the file size is a real number you can sort, compare and add up. A text-based shell would … Read more

How to Generate Random Numbers in PowerShell (7 and 5.1)

Generate random numbers in PowerShell with Get-Random and .NET

Need a random number between 1 and 10? To generate random numbers in PowerShell, call Get-Random with a range, and remember the maximum is never returned: That prints a whole number from 1 to 10. Below, I cover decimals, several numbers at once, seeds, 6-digit codes, .NET options and secure numbers, each tested in PowerShell … Read more

PowerShell Pipeline Variables: $_, $PSItem and -PipelineVariable

PowerShell pipeline variables with $_, $PSItem and -PipelineVariable

PowerShell pipeline variables come in two kinds: the automatic $_ (also called $PSItem), which holds the current object, and the -PipelineVariable common parameter, which saves an object under your own name for later pipeline steps: Output: Here $order still points at the CSV row two commands later, while $PSItem is whatever reached the current command. … Read more

How to Get the Computer Name in PowerShell (7 and 5.1)

Get computer name in PowerShell with five methods compared

The fastest way to get the computer name in PowerShell is the COMPUTERNAME environment variable. Type this and press Enter: It works the same in PowerShell 7 and Windows PowerShell 5.1 on Windows. The other methods below return almost the same thing, but they differ in letter case, in remote support, and on Linux or … Read more

How to Convert a Relative Path to an Absolute Path in PowerShell

Convert a relative path to an absolute path in PowerShell

To convert a relative path to an absolute path in PowerShell, use Resolve-Path. It resolves the path against your current PowerShell location and returns the full path: Resolve-Path only works for paths that exist, though, and the popular .NET shortcut can quietly use the wrong folder. Below I cover both problems, plus paths relative to … Read more

How to Convert an Object to a String in PowerShell

Convert an object to a string in PowerShell

To convert an object to a string in PowerShell, pipe it to Out-String, which returns the same text you’d see in the console. Add .Trim() to drop the blank lines around it: That works for custom objects, cmdlet output and hashtables. When you want one value in a sentence, you’ll use property expansion, JSON or … Read more

How to Count Occurrences of a Substring in a String in PowerShell

Count occurrences of a substring in a string in PowerShell

To count occurrences of a substring in a string in PowerShell, escape the substring and count the regex matches. This one line returns how many times $find appears in $text: The count you get depends on case, special characters and overlaps, and a few popular shortcuts quietly get it wrong. I ran each method below … 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