This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Get-Item.
When to use Get-Item?
The Get-Item cmdlet gets the item at the specified location. It does not get the contents of the item at the location unless you use a wildcard character (*) to request all the contents of the item.
This cmdlet is used by PowerShell providers to navigate through different types of data stores.
What version of PowerShell am I using?
Get the PowerShell Version from your machine:
This command shows you the PowerShell version information on your machine.
How to use Get-Item?
Get the current directory:
This example gets the current directory. The dot (‘.’) represents the item at the current location (not its contents).
Get all the items in the current directory:
This example gets all the items in the current directory. The wildcard character (*) represents all the contents of the current item.
Get the current directory of a drive:
This example gets the current directory of the C: drive. The object that is retrieved represents only the directory, not its contents.
Get items in the specified drive:
This example gets the items in the C: drive. The wildcard character (*) represents all the items in the container, not just the container.
In PowerShell, use a single asterisk (*) to get contents, instead of the traditional *.*. The format is interpreted literally, so *.* would not retrieve directories or filenames without a dot.
Get-Item C:\ *
Get a property in the specified directory:
This example gets the LastAccessTime property of the C:\Windows directory. LastAccessTime is just one property of file system directories. To see all the properties of a directory, type (Get-Item <directory-name>) | Get-Member.
Show the contents of a registry key:
This example shows the contents of the Microsoft.PowerShell registry key. You can use this cmdlet with the PowerShell Registry provider to get registry keys and subkeys, but you must use the Get-ItemProperty cmdlet to get the registry values and data.
Learn last week’s command: Get-TimeZone.
Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.