The Get-Item cmdlet gets the items at a particular location. This cmdlet does not get the content of item at the specified location unless we use a ‘*‘ wildcard character to request all the content of the item.
PowerShell providers use this command to navigate through a different type of data stores.
The -Path parameter specifies the path to an item. The characters of wildcard are accepted. The -Path parameter is required, but the name ‘-Path‘ is optional.
You can use a ‘.’ to specify a current location. To specify all the items in the current location, use a ‘*’ asterisk.
The -LiteralPath parameter specifies a path to one or more location. Its value is used exactly as it is typed. Wildcards characters are not interpreted. If the path includes any escape character, then enclosed it in quotation marks. Single quotation mark tells the Windows PowerShell not to interpret any character as an escape sequence.
The -Force parameter indicate those items which cannot be accessed by a user such as hidden files. The implementation of this parameter is varied from provider to provider. Even using the -Force parameter, the cmdlet cannot override the security permissions.
The -Include parameter specifies as a string array, an item. It also specifies those items which this cmdlet includes in the operation. The value of -Include parameter qualifies the Path parameter. Enter a pattern or a path element, such as ‘*.txt‘.
This parameter is effective only when a cmdlet includes the contents of an item, such as ‘C:Windows*‘, where the wildcard character ‘*‘ specifies the contents of the C:Windows directory.
The -Filter parameter is used to specify a filter to qualify the -Path parameter. The file system provider is the only installed provider of PowerShell, which supports the use of filters. This parameter is more efficient than other parameters because a provider applies them when the cmdlet retrieves the object, rather than having PowerShell filters the object after they are retrieved.
The -Exclude parameter specifies as a string array, a property. It also specifies those items which this cmdlet excludes from the operation. The value of -Exclude parameter qualifies the Path parameter. Wildcards characters are accepted.
Enter a pattern or a path element, such as A* or *.txt. Wildcard characters are permitted.
The -Stream parameter is used to get the particular alternate NTFS file stream from the file. Wildcard characters are supported. Use an asterisk ‘*‘ character to get all the streams. The -Stream parameter is not valid on folders.
It is a dynamic parameter and works only in the file system drives.
Example 1: To get the current location
The cmdlet in this example is used to get the current working location. The dot ‘.‘ Operator represents the item at current directory but not it’s content.
Example 2: To get all the items in the current location
The cmdlet in this example is used to access all the items in the current working directory. The asterisk ‘*‘ character represents all the content of the current item.
Example 3: To get all the items in the specified directory or location
The cmdlet in this example is used to get all the items of a directory given in the cmdlet. Use the asterisk ‘*‘ character to show the content of the container, not just the container.
Example 4: To get a property in the specified location
The cmdlet in this example shows the LastAccessTime property of the directory, which is given in the cmdlet. LastAccessTime is a property of file system directories. Use this cmdlet (Get-Item ) | Get-Member> to see all the properties of a given directory.
Example 5: To display the content of a registry key
The cmdlet, in this example, displays the content of Microsoft.PowerShell registry key. We can use this cmdlet with the PowerShell registry provider to show the registry keys and subkeys, but we must use the Get-ItemProperty cmdlet to get the values and data of the registry.