Edit

Share via


Get-Item

Gets the item at the specified location.

Syntax

Get-Item
   [-Path] <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [-Stream <string[]>]
   [<CommonParameters>]
Get-Item
   -LiteralPath <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [-Stream <string[]>]
   [<CommonParameters>]
Get-Item
   [-Path] <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [-CodeSigningCert]
   [-DocumentEncryptionCert]
   [-SSLServerAuthentication]
   [-DnsName <string>]
   [-Eku <string[]>]
   [-ExpiringInDays <int>]
   [<CommonParameters>]
Get-Item
   -LiteralPath <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [-CodeSigningCert]
   [-DocumentEncryptionCert]
   [-SSLServerAuthentication]
   [-DnsName <string>]
   [-Eku <string[]>]
   [-ExpiringInDays <int>]
   [<CommonParameters>]
Get-Item
   [-Path] <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [<CommonParameters>]
Get-Item
   -LiteralPath <string[]>
   [-Filter <string>]
   [-Include <string[]>]
   [-Exclude <string[]>]
   [-Force]
   [-Credential <pscredential>]
   [<CommonParameters>]

Description

The Get-Item cmdlet gets the item at the specified location. It doesn't 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.

Examples

Example 1: Get the current directory

This example gets the current directory. The dot ('.') represents the item at the current location (not its contents).

Get-Item .

Directory: C:\

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         7/26/2006  10:01 AM            ps-test

Example 2: 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-Item *

Directory: C:\ps-test

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         7/26/2006   9:29 AM            Logs
d----         7/26/2006   9:26 AM            Recs
-a---         7/26/2006   9:28 AM         80 date.csv
-a---         7/26/2006  10:01 AM         30 filenoext
-a---         7/26/2006   9:30 AM      11472 process.doc
-a---         7/14/2006  10:47 AM         30 test.txt

Example 3: 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-Item C:

Example 4: 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.

Get-Item C:\*

In PowerShell, use a single asterisk (*) to get contents, instead of the traditional *.*. The format is interpreted literally, so *.* wouldn't retrieve directories or filenames without a dot.

Example 5: 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.

(Get-Item C:\Windows).LastAccessTime

Example 6: 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.

Get-Item HKLM:\Software\Microsoft\PowerShell\1\Shellids\Microsoft.PowerShell\

Example 7: Get items in a directory that have an exclusion

This example gets items in the Windows directory with names that include a dot (.), but don't begin with w*.This example works only when the path includes a wildcard character (*) to specify the contents of the item.

Get-Item C:\Windows\*.* -Exclude "w*"

In PowerShell 6.2, an alternate view was added to get hardlink information. To get the hardlink information, pipe the output to Format-Table -View childrenWithHardlink

Get-Item C:\Windows\System32\ntoskrnl.exe |
    Format-Table -View childrenWithHardLink

Directory: C:\Windows\System32

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
la---           5/12/2021  7:40 AM       10848576 ntoskrnl.exe

The Mode property identifies the hardlink by the l in la---

Example 9: Output for Non-Windows Operating Systems

In PowerShell 7.1 on Unix systems, the Get-Item cmdlet provides Unix-like output:

PS> Get-Item /Users

Directory: /

UnixMode    User  Group   LastWriteTime      Size  Name
--------    ----  -----   -------------      ----  ----
drwxr-xr-x  root  admin   12/20/2019 11:46   192   Users

The new properties that are now part of the output are:

  • UnixMode is the file permissions as represented on a Unix system
  • User is the file owner
  • Group is the group owner
  • Size is the size of the file or directory as represented on a Unix system

Note

This feature was moved from experimental to mainstream in PowerShell 7.1.

Parameters

-CodeSigningCert

This is a dynamic parameter made available by the Certificate provider. This parameter and the Certificate provider are only available on Windows.

To get certificates that have Code Signing in their EnhancedKeyUsageList property value, use the CodeSigningCert parameter.

For more information, see about_Certificate_Provider.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Credential

Note

This parameter isn't supported by any providers installed with PowerShell. To impersonate another user, or elevate your credentials when running this cmdlet, use Invoke-Command.

Type:PSCredential
Position:Named
Default value:Current user
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-DnsName

This is a dynamic parameter made available by the Certificate provider. This parameter and the Certificate provider are only available on Windows.

Specifies a domain name or name pattern to match with the DNSNameList property of certificates the cmdlet gets. The value of this parameter can either be Unicode or ASCII. Punycode values are converted to Unicode. Wildcard characters (*) are permitted.

This parameter was reintroduced in PowerShell 7.1

For more information, see about_Certificate_Provider.

Type:DnsNameRepresentation
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-DocumentEncryptionCert

This is a dynamic parameter made available by the Certificate provider. This parameter and the Certificate provider are only available on Windows.

To get certificates that have Document Encryption in their EnhancedKeyUsageList property value, use the DocumentEncryptionCert parameter.

For more information, see about_Certificate_Provider.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Eku

This is a dynamic parameter made available by the Certificate provider. This parameter and the Certificate provider are only available on Windows.

Specifies text or a text pattern to match with the EnhancedKeyUsageList property of certificates the cmdlet gets. Wildcard characters (*) are permitted. The EnhancedKeyUsageList property contains the friendly name and the OID fields of the EKU.

This parameter was reintroduced in PowerShell 7.1

For more information, see about_Certificate_Provider.

Type: