
Share this post:This blog post is part of an ongoing series by Adam Gordon. Adam will walk through each PowerShell command every week, explaining when and how to use them. Adam will be covering Get-Item this week.
When is it appropriate to use the Get-Item feature?
The Get-Item cmdlet will get the item at the requested location. It will not retrieve the contents of an item at the specified location unless you use wildcard characters (*) to request all of them.
This cmdlet can be used by PowerShell providers for navigation through different types of data storage.
What version of PowerShell do I use?
Get the PowerShell Version for your machine
$PSVersionTable
This command displays the PowerShell version information for your machine.
How to use Get-Item
Get the most current directory:
Get-Item .
This example will display the current directory. The (‘.’) dot represents the current directory. The dot (‘.’) represents the item at its current location (not its contents).
All the items in the current directory are available:
This example shows all items in the current directory. The wildcard character (*), represents all of the contents of the current item.
Get-Item *
Get the most current directory for a drive:
This example retrieves the current directory on the C: drive. The object that is returned represents the directory and not its contents.
Get-Item C:\
You can get the items you need in the specified drive
This example will get the items in the C drive. The wildcard character * represents all items in the container.
PowerShell uses a single asterisk * to get contents instead of the *.*.. The format is taken literally, so *. Without a dot, * would not retrieve files or directories.
Get-Item C:\ *
Find a property in the directory you are interested in:
This example obtains the LastAccessTime property from the C:Windows directory. LastAccessTime is only one property of file systems directories. Get-Member.
(Get-Item C:\Windows).LastAccessTime
Show the contents of a registry-key:
This example shows the contents for the Microsoft.PowerShell Registry key. This cmdlet can be used with the PowerShell Registry provider for registry keys and subkeys. However, you will need to use the Get-ItemProperty cmdlet in order to obtain the registry values or data.
Get-Item HKLM:\Software\Microsoft\Powershell\1\Shellids\Microsoft.Powershell\
Get-TimeZone reveals the command last week.
Do you need PowerShell training? ITProTV offers PowerShell online IT training courses.