PowerShell Get-Date UTC: Get, Format and Convert UTC Time

PowerShell Get-Date UTC examples

Need the current time in UTC? In PowerShell 7.1 and later, Get-Date -AsUTC returns it directly. Windows PowerShell 5.1 doesn’t have that switch, so use [datetime]::UtcNow there, which works in every version: Both return a DateTime whose Kind is Utc. Below I’ll format UTC values, convert them to and from US time zones, parse UTC … Read more

How to Create Multiple Folders in PowerShell (New-Item, Loops, CSV)

Create multiple folders in PowerShell

To create multiple folders in PowerShell, give New-Item a comma-separated list of paths: New-Item -ItemType Directory -Path C:\Data\A, C:\Data\B. The -Path parameter takes an array, so one command makes them all. For dozens of folders, read the names from a list, a number range or a CSV and loop over them. I tested each method … Read more

PowerShell Get-Process: List, Filter, Sort and Stop Processes

PowerShell Get-Process cmdlet

PowerShell Get-Process lists the processes running on your computer. Type Get-Process for all of them, or Get-Process -Name chrome for one app by name. Each result is a Process object you can sort, filter or stop. I’ll go through names, IDs, sorting by CPU and memory, owners, modules and remote computers. I ran each example … Read more

PowerShell Write-Warning: Show, Hide and Capture Warnings

PowerShell Write-Warning with examples

PowerShell Write-Warning shows a yellow WARNING: message without stopping your script. Use it for problems the user should know about but that aren’t errors: Warnings go to their own stream, so callers can hide, capture or escalate them. Below I show each option with a small disk check function. Every example gave the same output … Read more

How to Run a PowerShell Script in PowerShell ISE

How to run a PowerShell script in PowerShell ISE

To run a PowerShell script in PowerShell ISE, open the .ps1 file with File > Open (Ctrl+O) and press F5, or click the green Run Script button. To run only part of the script, select those lines and press F8. The output shows in the console pane under the script. The ISE runs Windows PowerShell … Read more

How to Convert UTF-16 to UTF-8 Using PowerShell

Convert UTF-16 to UTF-8 using PowerShell

To convert a UTF-16 file to UTF-8 with PowerShell, read it with Get-Content and write it back with Set-Content -Encoding utf8: Get-Content recognizes UTF-16 by itself. The catch is the byte order mark: PowerShell 7 writes UTF-8 without one, and Windows PowerShell 5.1 adds it. Below I show the real bytes, a version that behaves … Read more

How to Remove Whitespace from Strings in PowerShell

Remove whitespace from strings in PowerShell

To remove whitespace from strings in PowerShell, use .Trim() for spaces at the start and end, or -replace ‘\s’, ” to strip every space, tab and line break: Which one you need depends on whether the spaces inside the text matter. I tested every example in PowerShell 7 and Windows PowerShell 5.1, including the invisible … Read more

How to Extract URLs from an XML Sitemap Using PowerShell

Extract URLs from an XML sitemap using PowerShell

To extract URLs from an XML sitemap using PowerShell, cast the file to [xml] and read the loc element of every url entry: That returns every URL as plain text. Below I filter them by keyword, remove duplicates, handle sitemap index files, and save the list. I tested each step in PowerShell 7 and Windows … Read more

How to Find Duplicate Files Using PowerShell

Find duplicate files using PowerShell

To find duplicate files with PowerShell, hash every file with Get-FileHash and group the results by hash. Files with the same hash have the same content, whatever their names are: Below I run it on a sample folder, speed it up for big folders, catch same-name files that differ, plan a safe cleanup and compare … Read more