How to Set a Proxy in PowerShell (7 and 5.1)

Set a proxy in PowerShell

To set a proxy in PowerShell for one request, pass it to -Proxy on Invoke-WebRequest or Invoke-RestMethod. Add -ProxyUseDefaultCredentials if the proxy needs your Windows sign-in: For a whole session, the method differs between PowerShell 7 and Windows PowerShell 5.1. I cover both below, plus bypass lists and the Windows-wide proxy. The proxy server in … Read more

PowerShell Get-ChildItem Filter Examples

PowerShell Get-ChildItem filter examples

To filter files with Get-ChildItem, pass a wildcard pattern to -Filter. Add -Recurse to search subfolders too: Output: -Filter is the fastest option because the file system does the matching. Below I compare it with -Include and -Exclude, show a gotcha that returns nothing, and filter by date and size. All of it runs in … Read more

PowerShell Switch Parameter (With Examples)

PowerShell switch parameter with examples

A PowerShell switch parameter is a parameter of type [switch] that’s on when you include it and off when you leave it out. It takes no value, like -Force or -Recurse: Output: Below I cover how to pass an explicit value, tell whether the caller used the switch, forward it to another function and name … Read more

How to Disable Windows Firewall Using PowerShell

Disable Windows Firewall using PowerShell

To disable Windows Firewall using PowerShell, open PowerShell as administrator and set all three firewall profiles to False: That leaves the PC unprotected, so turn it back on as soon as you’re done. Below I check the status, preview the change with -WhatIf, re-enable it, and show the safer option of changing one rule. My … Read more

How to Set the Default Printer Using PowerShell in Windows

Set the default printer using PowerShell

To set the default printer using PowerShell, get the printer from Win32_Printer and call its SetDefaultPrinter method with Invoke-CimMethod: It works for the current user and doesn’t need admin rights. Below I list printers, check the default, preview the change with -WhatIf and stop Windows from switching it back. My own default stayed untouched. List … Read more

How to Get Computer Information Using PowerShell

Get computer information using PowerShell

To get computer information using PowerShell, run Get-ComputerInfo. It returns more than 180 properties about Windows, the hardware and the BIOS. Pick the ones you need with -Property: Output: Notice WindowsProductName says Windows 10 on this Windows 11 PC. It’s a long-standing quirk, and below I show a more reliable way, plus a faster CIM … Read more

How to Create a Self-Signed Certificate Using PowerShell

Create a self-signed certificate using PowerShell

To create a self-signed certificate using PowerShell, run New-SelfSignedCertificate with the DNS names and the certificate store to save it in. The current-user store doesn’t need admin rights: Below I show what a self-signed certificate contains, how to export it as .cer and .pfx files, and how to trust it for testing. To keep my … Read more

PowerShell Filter Operators (With Examples)

PowerShell filter operators with examples

PowerShell filter operators are the comparison operators, like -eq, -gt, -like, -match and -in, used to keep only the items you want. Put them inside Where-Object, or apply them straight to an array: Output: When the left side is an array, the operator returns the matching items instead of True or False. Below I cover … Read more

PowerShell Functions: Return Values and Multiple Values

PowerShell functions return values

A PowerShell function returns every value it outputs, not just what follows the return keyword. Any expression you don’t assign or discard goes back to the caller: Output: return only ends the function early. Below I show the most common surprise with extra output, and the clean ways to return one value, several values or … Read more