Retrieving a Specific Item From PowerShell
The Get-Item cmdlet makes it easy to retrieve a specific item (such as a file, a folder, or a registry key). For one thing, it makes it very easy to retrieve the properties of those items. For example, suppose you’d like to know the last time someone accessed the C:\scripts folder:

Code:

$(Get-Item c:\scripts).lastaccesstime


We’re using Get-Item to create an object reference to C:\Scripts. That’s the reason for the unusual syntax: the command itself - Get-Item c:\scripts - is enclosed in parentheses, with a $ pasted on front. The property we’re interested in is then tacked on using standard dot notation (object.property). Want to know the number of subkeys found in HKEY_CURRENT_USER\Software? Here how:

Code:

$(Get-Item hkcu:\software).subkeycount


How did we know that SubkeyCount was a property of a registry key? Well, to tell you the truth, we didn’t. But that’s another good use for Get-Item: we simply used Get-Item to return an object representing HKEY_CURRENT_USER\Software and then piped that object to the Get-Member cmdlet:

Code:

Get-Item hkcu:\software | Get-Member


We then left it up to Get-Member to figure out the properties of the registry key.

Get-Item Aliases:

gu