get-itemProperty
return a
psCustomObject that contains the properties that were requested with
get-itemProperty
from an
item's
. Typically, such properties are those of files and directorys (such as
lastWriteTime
,
attributes
etc.).
Returned data type
$scriptName = $myInvocation.myCommand.name
$propFile = get-itemProperty $scriptName
$propFile.GetType().FullName
#
# System.IO.FileInfo
$propFileattr = get-itemProperty $scriptName lastAccessTime
$propFileattr.GetType().FullName
#
# System.Management.Automation.PSCustomObject
$propDir = get-itemProperty .
$propDir.GetType().FullName
#
# System.IO.DirectoryInfo
$propRegKey = get-itemProperty 'HKCU:\Control Panel\International'
$propRegKey.GetType().FullName
#
# System.Management.Automation.PSCustomObject
$propVal = get-itemProperty 'HKCU:\Control Panel\International' sTimeFormat
$propVal.GetType().FullName
#
# System.Management.Automation.PSCustomObject
$propVal.sTimeFormat.GetType().FullName
#
# System.String
$val = get-itemPropertyValue 'HKCU:\Control Panel\International' sTimeFormat
$val.GetType().FullName
#
# System.String
returning psCustomObject
When
get-itemProperty
returns a
psCustomObject
, this object has the (additional) properties:
psPath
,
psParentpath
,
psChildname
,
psDrive
,
psProvider
(See also
item
related properties).
Therefore, if
get-itemProperty
is used to display a
registry value, more information is printed than is probably needed:
PS C:\> get-itemProperty hkcu:\Environment -name PATH
Path : C:\Users\rene\bin;c:\users\rene\MinGW64\bin;…
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Environment
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER
PSChildName : Environment
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
So, in order to only get a value, the value name (which becomes a property in the PSCustomObject
that is returned) needs to be queried:
PS C:\> (get-itemProperty hkcu:\Environment -name PATH).PATH
C:\Users\rene\bin;c:\users\rene\MinGW64\bin;…
Change file attributes
The following command add the archive file attribute to a given file:
( get-ItemProperty .\some.txt ).attributes += 'archive'