How to Write a Variable to a CSV File in PowerShell

Write a variable to a CSV file in PowerShell

To write a variable to a CSV file in PowerShell, put the values in a [pscustomobject] and pipe it to Export-Csv. Each property becomes a column: Piping a plain string or a hashtable gives you a surprising file instead. Below I show what goes wrong, and how to write strings, arrays, hashtables and loop results … Read more

How to Find an IP Address from a MAC Address in PowerShell

PowerShell 7 console finding the IP address for a MAC address with Get-NetNeighbor

PowerShell finds an IP address from a MAC address by searching the neighbor cache, which is the ARP table for IPv4. Pass the MAC to Get-NetNeighbor: In this tutorial, I’ll show you how to find an IP from a MAC address in PowerShell with Get-NetNeighbor and arp -a, which MAC formats work, what to do … Read more

How to Check Free Memory in PowerShell (CIM and Get-Counter)

PowerShell 7 console showing free memory, total memory and percent used from Win32_OperatingSystem

Want to check free memory in PowerShell? Query the Win32_OperatingSystem class and read FreePhysicalMemory, which Windows reports in kilobytes: In this tutorial, I’ll show you how to check free memory in PowerShell with Get-CimInstance and Get-Counter, compare installed and usable RAM, see what processes use, and wrap it all in a function. My test machine … Read more

How to Get Dell Service Tag Using PowerShell (7 and 5.1)

Get Dell service tag using PowerShell with Get-CimInstance Win32_BIOS

A Dell service tag is the BIOS serial number, so the quickest way to get the Dell service tag using PowerShell is one CIM query. It works in Windows PowerShell 5.1 and PowerShell 7: In this guide, I’ll show you how to get the Dell service tag using PowerShell on your own PC, why Dell’s … Read more

How to Find the Largest Folders Using PowerShell

Find the largest folders using PowerShell

To find the largest folders using PowerShell, add up the file sizes in each folder with Measure-Object and sort the results. Windows doesn’t store folder sizes, so you have to calculate them: Below I run it on a sample folder, show the top folders in friendly units, search every subfolder level and list the largest … Read more

How to Remove a Computer from a Domain Using PowerShell

Remove a computer from a domain with PowerShell

To remove a computer from a domain with PowerShell, run Remove-Computer as administrator, name the workgroup to join and restart: The credential needs rights to remove the computer account. Below I check the join state, preview the command, remove remote PCs and clean up AD. My test PC isn’t on a domain, so I used … Read more

How to Find the OU of a Computer Using PowerShell

Find the OU of a computer using PowerShell

To find the OU of a computer using PowerShell, get its DistinguishedName with Get-ADComputer and drop the first CN= part. What’s left is the OU path: Get-ADComputer needs the ActiveDirectory module from RSAT. Below I check the prerequisites, show the parsing step on sample Contoso names, and cover bulk lookups and a method that doesn’t … Read more

ConvertTo-Json in PowerShell (With Examples)

PowerShell ConvertTo-Json

ConvertTo-Json turns PowerShell objects, hashtables and arrays into JSON text. Pipe the data to it, and use [ordered] so the keys keep your order: Output in PowerShell 7: Output in Windows PowerShell 5.1: Both are valid JSON with the same data, only the spacing differs. I ran every example in PowerShell 7.6 and Windows PowerShell … 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