Windows PowerShell is a powerful command-line shell and scripting language designed for system administrators and power users. It is included in all versions of Windows since Windows 7 and Windows Server 2008 R2. One of the most useful commands in Windows PowerShell is the Get-ItemProperty command. This command allows you to retrieve the properties of a file or folder on your computer.
In this article, we will discuss the Get-ItemProperty command in detail, including its syntax, parameters, inputs, outputs, examples, and tips. We will also answer some of the most common questions about the command.
What is the Get-ItemProperty Command?
The Get-ItemProperty command is a Windows PowerShell cmdlet that retrieves the properties of a file or folder on your computer. It can be used to get information about a file or folder, such as its size, date created, date modified, and more. It can also be used to retrieve the properties of a registry key.
Syntax of the Get-ItemProperty Command
The syntax of the Get-ItemProperty command is as follows:
Get-ItemProperty [-Path] <String[]> [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-Name <String[]>] [-LiteralPath <String[]>] [-Credential <PSCredential>] [-UseTransaction] [-Force] [-Stream <String>] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-WarningAction <ActionPreference>] [-WarningVariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>] [-WhatIf] [-Confirm] [ <CommonParameters>]
Parameters of the Get-ItemProperty Command
The Get-ItemProperty command has the following parameters:
Parameter | Description |
---|---|
Path | Specifies the path to the item for which you want to retrieve properties. |
Filter | Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. |
Include | Specifies the items to include in the operation. Wildcards are permitted. |
Exclude | Specifies the items to exclude from the operation. Wildcards are permitted. |
Name | Specifies the names of the properties to retrieve. |
LiteralPath | Specifies the path to the item for which you want to retrieve properties. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed. |
Credential | Specifies a user account that has permission to perform this action. |
UseTransaction | Includes the command in the active transaction. |
Force | Forces the command to run without asking for user confirmation. |
Stream | Specifies the name of the alternate data stream to retrieve. |
ErrorAction | Specifies how the command should handle errors. |
ErrorVariable | Specifies a variable in which the command should store any errors that it generates. |
WarningAction | Specifies how the command should handle warnings. |
WarningVariable | Specifies a variable in which the command should store any warnings that it generates. |
OutVariable | Specifies a variable in which the command should store the objects that it generates. |
OutBuffer | Specifies the maximum number of objects to store in the output buffer. |
WhatIf | Describes what would happen if the command were to run. |
Confirm | Prompts the user for confirmation before running the command. |
Inputs of the Get-ItemProperty Command
The Get-ItemProperty command accepts the following inputs:
- System.String[]
- System.Management.Automation.PSCredential
- System.Management.Automation.SwitchParameter
Outputs of the Get-ItemProperty Command
The Get-ItemProperty command generates the following outputs:
- System.Object
- System.Management.Automation.ErrorRecord
- System.Management.Automation.WarningRecord
Examples of the Get-ItemProperty Command
The following examples show how to use the Get-ItemProperty command:
- To retrieve the properties of a file, use the following command:
Get-ItemProperty -Path C:\example\file.txt
- To retrieve the properties of a folder, use the following command:
Get-ItemProperty -Path C:\example\folder
- To retrieve the properties of a registry key, use the following command:
Get-ItemProperty -Path HKLM:\Software\Microsoft
- To retrieve the properties of a file, including the size and date modified, use the following command:
Get-ItemProperty -Path C:\example\file.txt -Name Size, DateModified
- To retrieve the properties of a folder, excluding hidden files, use the following command:
Get-ItemProperty -Path C:\example\folder -Exclude *.hidden
Tips for Using the Get-ItemProperty Command
Here are some tips for using the Get-ItemProperty command:
- Use the Path parameter to specify the path to the item for which you want to retrieve properties.
- Use the Filter parameter to specify a filter in the provider’s format or language.
- Use the Include and Exclude parameters to specify the items to include or exclude from the operation.
- Use the Name parameter to specify the names of the properties to retrieve.
- Use the LiteralPath parameter to specify the path to the item for which you want to retrieve properties. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed.
- Use the Credential