How to Get the Length of a String in PowerShell

Get the length of a string in PowerShell

To get the length of a string in PowerShell, read its .Length property. It returns the number of characters, including spaces: Output: That works for everyday text. Arrays, numbers, emoji and byte counts behave differently, and I cover each one below. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, with the same … Read more

PowerShell Multidimensional Arrays (Jagged and 2D)

PowerShell multidimensional arrays

A multidimensional array in PowerShell is usually an array of arrays, called a jagged array. Each inner array is a row, and you read a value with two indexes, $array[row][column]: Output: PowerShell also has true two-dimensional arrays like [int[,]], covered further down. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1, with the … Read more

How to Convert Seconds to Hours and Minutes in PowerShell

Convert seconds to hours and minutes in PowerShell

To convert seconds to hours and minutes in PowerShell, turn the number into a TimeSpan with New-TimeSpan -Seconds. Its Hours, Minutes and Seconds properties hold the parts, and ToString formats it as hh:mm:ss: Output: The backslashes in ‘hh\:mm\:ss’ are required, because a colon means something special in TimeSpan formats. Every example ran in PowerShell 7.6 … Read more

How to Clear PowerShell History (Session and PSReadLine)

Clear PowerShell history with Clear-History and the PSReadLine history file

To clear PowerShell history completely, clear the session list and delete the PSReadLine history file, which is what the Up arrow reads from: Then close and reopen PowerShell. Below I show both kinds of history, how to remove only one sensitive line, and how to stop PowerShell from saving commands. PowerShell keeps two kinds of … Read more

How to Get the BIOS Version Using PowerShell

Get BIOS version using PowerShell

To get the BIOS version with PowerShell, run (Get-CimInstance -ClassName Win32_BIOS).SMBIOSBIOSVersion. It works in PowerShell 7 and Windows PowerShell 5.1 and doesn’t need admin rights: Output: I replaced this PC’s real BIOS details with placeholders like Contoso, 1.24.0 and ABC1234XYZ, and blacked them out in the screenshots. Your output will show your own values. Get … Read more

How to Get the BIOS Serial Number Using PowerShell

Get the BIOS serial number using PowerShell

To get the BIOS serial number using PowerShell, read the SerialNumber property of the Win32_BIOS class. One line does it, with no admin rights needed: Output: That’s the same number printed on the sticker of most laptops and desktops. Below I compare the other places Windows stores serials, replace the old wmic command, and collect … Read more

How to Check Hard Drive Space Using PowerShell

Check hard drive space using PowerShell

To check hard drive space using PowerShell, run Get-Volume. It shows the free space (SizeRemaining) and total size of each drive, and it works without admin rights in Windows PowerShell 5.1 and PowerShell 7: Output: For a report you can reuse, including free space in GB, percent free and remote servers, query Win32_LogicalDisk. I’ll build … Read more

How to List Scheduled Tasks with PowerShell

List scheduled tasks with PowerShell

To list scheduled tasks with PowerShell, run Get-ScheduledTask. It returns every task you have permission to see, with its folder, name and state: On a typical PC that’s a couple of hundred tasks. Below I narrow the list by folder, name and state, read run results, see what each task runs, query remote PCs and … Read more

PowerShell Add-Content: Append Text to a File

PowerShell Add-Content: append text to a file

To append text to a file in PowerShell, use Add-Content with the file path and the text. It adds the text as a new line at the end, and leaves everything already in the file alone: Output: I ran every example in PowerShell 7.6 and Windows PowerShell 5.1. Most behave the same, but mixing Add-Content … Read more

PowerShell Test-NetConnection: Test Ports, Ping and Routes

PowerShell Test-NetConnection examples

Test-NetConnection checks whether your computer can reach another host, and whether a specific TCP port on it is open. Give it a computer name and a port: Output: TcpTestSucceeded True means the port accepted a connection. I selected three properties because the full output also lists your own IP address and network adapter. Every example … Read more