Get-Item

 

Additional Resources for Get-Item

 

Retrieving a Specific Item

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-item.mspx

 

 

SYNOPSIS

Gets the item at the specified location.

 

SYNTAX

Get-Item [-path] <string[]> [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-credential <PSCredential>] [<CommonParameters>]

 

Get-Item [-literalPath] <string[]> [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-credential <PSCredential>] [<CommonParameters>]

 

DETAILED DESCRIPTION

The Get-Item cmdlet gets the item at the specified location. It does not get contents of the item at the location, unless you use a wildcard character (*) to request all contents of the item.

 

The Get-Item cmdlet is used by Windows PowerShell providers to enable you to navigate through different types of data stores.

 

PARAMETERS

 

-path <string[]>

Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are permitted. This parameter is required, but the parameter name ("-Path") is optional.

 

Use a dot (.) to specify the current location. Use the wildcard character (*) to specify the all items in the current location.

 

Required?

true

Position?

1

Default value

<Current Location>

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

true

 

-include <string[]>

Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.

 

The Include parameter is effective only when the command includes the contents of a item, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-exclude <string[]>

Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.

 

The Exclude parameter is effective only when the command includes the contents of a item, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-filter <string>

Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-credential <PSCredential>

Uses a credential to validate access to the file. <Credential> represents a user-name, such as "User01" or "Domain01\User01", or a PSCredential object, such as the one retrieved by using the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter appears, but it is not supported in any Windows PowerShell core cmdlets or providers.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-literalPath <string[]>

Specifies a path to the item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

 

Required?

true

Position?

1

Default value

 

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

String

 

RETURN TYPE

Any

 

NOTES

 

For more information, type "Get-Help Get-Item -detailed". For technical information, type "Get-Help Get-Item -full".

 

Get-Item does not have a Recurse parameter, because it gets only an item, not its contents. To get the contents of an item recursively, use Get-Childitem.

 

To navigate through the registry, use Get-Item to get registry keys and Get-ItemProperty to get registry values and data. The registry values are considered to be properties of the registry key.

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

You can also refer to Get-Item by its built-in alias, "gi". For more information, see About_Alias.

 

EXAMPLE 1

 

get-item .

 

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

 

Directory: Microsoft.PowerShell.Core\FileSystem::C:\

 

Mode  LastWriteTime       Length Name

----  -------------       ------ ----

d---- 7/26/2006  10:01 AM        ps-test

 

EXAMPLE 2

 

get-item *

 

This command gets all items in the current directory. The wildcard character (*) represents all contents of the current item.

 

Directory: Microsoft.PowerShell.Core\FileSystem::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-item C:\

 

This command gets the current directory of the C: drive. The object that is retrieved represents only the directory, not its contents.

 

EXAMPLE 4

 

get-item C:\*

 

This command gets the items in the C: drive. The wildcard character (*) represents all items in the container, and not just the container.

 

In PowerShell, use a single asterisk (*) to get contents, instead of the traditional "*.*". In PowerShell, the form at is interpreted literally, so "*.*" would not retrieve directories or file names without a dot.

 

EXAMPLE 5

 

(get-item C:\Windows).LastAccessTime

 

This command gets the LastAccessTime property of the C:\Windows directory. LastAccessTime is just one property of file system directories. To see all of the properties of a directory, type "(Get-Item <directory-name>) | Get-Member".

 

EXAMPLE 6

 

get-item hklm:\software\microsoft\powershell\1\shellids\microsoft.powershell\*

 

This command shows the contents of the Microsoft.PowerShell registry key. You can use Get-Item with the Windows PowerShell Registry provider to get registry keys and subkeys, but you must use Get-ItemProperty to get the registry values and data.

 

EXAMPLE 7

 

get-item c:\Windows\* -include *.* -exclude w*

 

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

 

RELATED LINKS

Clear-Item

Copy-Item

Invoke-Item

Move-Item

Set-Item

New-Item

Remove-Item

Rename-Item

about_namespace