PowerShell: Get the Current Logged-On User on a Remote Computer

Get the current logged-on user on a remote computer with PowerShell

To get the current logged-on user on a remote computer with PowerShell, read the UserName property of Win32_ComputerSystem with Get-CimInstance: It returns DOMAIN\user for whoever is signed in at the console. Below I test the same queries on my own PC, show the two remoting errors you’ll most likely hit, and cover Remote Desktop sessions … Read more

How to Get All Files in a Directory Using PowerShell

Get all files in a directory using PowerShell

To get all files in a directory with PowerShell, run Get-ChildItem with the folder path and -File. -File leaves out the subfolders: Output: Without -File, you’d get the Archive and node_modules folders in the list too. Use -Directory when you want only folders. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1. Include … Read more

How to Create a Folder with the Current Date Using PowerShell

Create a folder with the current date in PowerShell

To create a folder with the current date in PowerShell, format today’s date as text and pass it to New-Item with -ItemType Directory: Output: I used a fixed date so the output doesn’t change. In a real script, use $today = Get-Date. Every example ran in PowerShell 7.6 and Windows PowerShell 5.1, with the same … Read more

How to Create Files with Content Using PowerShell (Text, JSON, XML)

Create files with content using PowerShell

To create a file with content in PowerShell, use Set-Content -Path file -Value ‘text’. It creates the file, or replaces its content if the file already exists: Output: Below I cover multiline text, encoding, and JSON and XML files. I ran every example in PowerShell 7.6 and Windows PowerShell 5.1 and show where they write … Read more

How to Find an HP Laptop Product Number Using PowerShell

Find an HP laptop product number with PowerShell

To find an HP laptop’s product number with PowerShell, read the SystemSKUNumber property of the Win32_ComputerSystem class. That’s the number printed on the sticker, the one HP support asks for: Output: I ran everything in this guide on an HP Pavilion laptop, in PowerShell 7.6 and Windows PowerShell 5.1. A product number and serial number … Read more

How to Install .NET Framework 3.5 Using PowerShell (Online and Offline)

Install .NET Framework 3.5 using PowerShell

To install .NET Framework 3.5 using PowerShell, enable the NetFx3 Windows feature in an elevated window. Windows downloads the files from Windows Update: That works on Windows 11 25H2 and earlier, Windows 10 and Windows Server. Windows 11 26H1 and later need a separate installer instead. Below I cover checking, installing online and offline, and … Read more

How to Set Folder Permissions Using PowerShell (Get-Acl, Set-Acl)

Set folder permissions using PowerShell

To set folder permissions using PowerShell, read the folder’s ACL with Get-Acl, add a FileSystemAccessRule, and write it back with Set-Acl. This grants the Users group Modify on a folder and everything inside it: Below I view permissions, grant and remove access, control inheritance and do the same with icacls. I tested everything on a … Read more

Set a Local User Password in Windows 11 with PowerShell

Set a password for a local user in Windows 11 with PowerShell

To set a password for a local user in Windows 11 with PowerShell, open PowerShell as administrator, read the new password as a secure string and pass it to Set-LocalUser: The password never appears on screen or in your history. Below I show how to check the account first, what the prompt looks like, the … Read more

How to Show Logged-In Users with PowerShell

Show logged-in users with PowerShell

To show logged-in users with PowerShell, run quser (short for query user). It lists every user signed in to the computer, including Remote Desktop sessions, with their session ID, state, idle time and logon time. Two other commands answer slightly different questions: Command What it returns Remote PCs quser Every signed-in user and session, active … Read more