Get ItemProperty - PowerShell


Overview

Get-ItemProperty retrieves the values of one or more properties for a specified item, such as a file, folder, registry key, or other object. It enables you to access and inspect specific attributes of items in the file system or other locations.

Syntax

Get-ItemProperty [[-Path] <string[]>] -Name <string[]> [-Force] [-Credential <PSCredential>] [-OutVariable <string>]

Options/Flags

  • -Path: Specifies the path to the item whose properties you want to retrieve. It can accept an array of paths.
  • -Name: Specifies the names of the properties you want to retrieve. It can also accept an array of property names.
  • -Force: Suppresses confirmation prompts when overwriting existing data.
  • -Credential: Specifies a PSCredential object to use for authentication.
  • -OutVariable: Stores the retrieved property values in the specified variable.

Examples

Example 1: Get the Creation Time of a File

Get-ItemProperty -Path "c:\myfile.txt" -Name CreationTime

Example 2: Retrieve Multiple Properties of a Folder

Get-ItemProperty -Path "c:\temp" -Name Name,LastAccessTime,CreationTime

Example 3: Get-ItemProperty with OutVariable

$propertyValues = Get-ItemProperty -Path "c:\myfile.txt" -Name CreationTime,LastAccessTime -OutVariable propertyValues

Common Issues

  • Access Denied: Ensure that you have sufficient permissions to access the specified item.
  • Property Not Found: Verify that the specified property name is valid for the item type.

Integration

Get-ItemProperty can be integrated with other commands to perform advanced tasks:

  • Get-ChildItem: Use Get-ChildItem to retrieve a list of items, then pipe the results to Get-ItemProperty to get their properties.
  • Set-ItemProperty: Use Get-ItemProperty to retrieve the current values of properties, modify them, and then use Set-ItemProperty to update the item.