PowerShell Cmdlet Deep Dive: Get-ItemProperty
Welcome back to Wahmans PowerShell Blog! Today we’re diving into one of the lesser-sung heroes of the PowerShell arsenal — Get-ItemProperty
. According to Microsoft, this cmdlet “gets the properties of a specified item.” Simple, right? But wait! Simplicity in PowerShell often hides surprisingly powerful capabilities. Let’s explore how this cmdlet can transform your scripting workflow — from basic to more advanced usage.
What is Get-ItemProperty
?
Get-ItemProperty
is a cmdlet that retrieves the properties of items like files, folders, registry keys, and more. It’s useful when you want to extract metadata or configuration details attached to these items.
📘 Examples
🔰 Example 1: Get properties of a file (Beginner)
Let’s start with the very basics. Suppose you want to look at the properties of a specific file on your disk:
Get-ItemProperty -Path "C:\Windows\System32\notepad.exe"
This command will list properties like Mode
, LastWriteTime
, Length
, etc., for the specified file.
🔍 Example 2: Get registry values (Intermediate)
Get-ItemProperty
really shines with the Windows Registry. Here’s how you can get the properties of a registry key:
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
This command pulls all the values under the CurrentVersion
registry key, which is useful for identifying OS version, product name, etc.
📋 Example 3: Extract a specific registry value (Intermediate)
Sometimes, you don’t need all the values — just one. Here’s how to extract the Windows Product Name:
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName
This will return something like Windows 10 Pro
or Windows 11 Home
, depending on your version.
⚙️ Example 4: List installed programs (Advanced)
Ok, now let’s step it up a notch. You can combine Get-ItemProperty
with Get-ChildItem
to read installed software from the registry:
Get-ChildItem -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" | \
ForEach-Object {
Get-ItemProperty $_.PsPath
} | Select-Object DisplayName, DisplayVersion, Publisher | \
Where-Object { $_.DisplayName } | Sort-Object DisplayName
This script lets you list all software installed on the machine (for the local machine context), a common task for system administrators.
🎯 Conclusion
Get-ItemProperty
is a versatile cmdlet that can be applied to a variety of use-cases — from checking file metadata to reading deep configuration settings from the Windows Registry. Understanding its power can help you unlock a lot of potential in your scripts.
Happy scripting, and I will see you in the next post!
Leave a Reply