Get-ItemPropertyValue

取得指定專案之一或多個屬性的值。

Syntax

Get-ItemPropertyValue
   [[-Path] <String[]>]
   [-Name] <String[]>
   [-Filter <String>]
   [-Include <String[]>]
   [-Exclude <String[]>]
   [-Credential <PSCredential>]
   [<CommonParameters>]
Get-ItemPropertyValue
   -LiteralPath <String[]>
   [-Name] <String[]>
   [-Filter <String>]
   [-Include <String[]>]
   [-Exclude <String[]>]
   [-Credential <PSCredential>]
   [<CommonParameters>]

Description

Get-ItemPropertyValue取得您在使用 Name 參數時所指定之屬性的目前值,該參數位於您使用 PathLiteralPath 參數指定的路徑中。

範例

範例 1:取得 ProductID 屬性的值

此命令會取得 Windows 登錄提供者中 “\SOFTWARE\Microsoft\Windows NT\CurrentVersion” 物件的 ProductID 屬性值。

Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ProductID

94253-50000-11141-AA785

範例 2:取得檔案或資料夾的最後一次寫入時間

此命令會從 FileSystem 提供者中,取得 C:\Program Files\PowerShell LastWriteTime 屬性的值,或檔案或資料夾上次變更的時間。

Get-ItemPropertyValue -Path 'C:\Program Files\PowerShell' -Name LastWriteTime

Wednesday, September 3, 2014 2:53:22 PM

範例 3:取得檔案或資料夾的多個屬性值

此命令會取得資料夾的 LastWriteTimeCreationTimeRoot 屬性的值。 屬性值會依照您指定屬性名稱的順序傳回。

Get-ItemPropertyValue -Path 'C:\Program Files\PowerShell' -Name LastWriteTime,CreationTime,Root

Tuesday, March 23, 2021 6:53:13 AM
Monday, August 14, 2017 1:42:40 PM

Parent              :
Root                : C:\
FullName            : C:\
Extension           :
Name                : C:\
Exists              : True
CreationTime        : 10/30/2015 1:28:30 AM
CreationTimeUtc     : 10/30/2015 6:28:30 AM
LastAccessTime      : 5/26/2021 9:22:24 AM
LastAccessTimeUtc   : 5/26/2021 2:22:24 PM
LastWriteTime       : 5/25/2021 7:25:08 AM
LastWriteTimeUtc    : 5/25/2021 12:25:08 PM
Attributes          : Hidden, System, Directory
Mode                : d--hs
ModeWithoutHardLink : d--hs
BaseName            : C:\
Target              :
LinkType            :

參數

-Credential

注意

任何與 PowerShell 一起安裝的提供者都不支援此參數。 若要模擬其他使用者,或在執行此 Cmdlet 時提升您的認證,請使用 Invoke-Command

Type:PSCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Exclude

指定此 Cmdlet 在作業中排除的專案或專案,做為字串陣列。 此參數的值會 限定Path 參數。 輸入路徑專案或模式,例如 *.txt。 允許通配符。 Exclude 參數只有在命令包含項目的內容時有效,例如 C:\Windows\*,通配符會指定目錄的內容C:\Windows

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Filter

指定篩選條件以限定 Path 參數。 FileSystem 提供者是唯一支援使用篩選器的已安裝 PowerShell 提供者。 您可以在 about_Wildcards 中找到 FileSystem 篩選語言的語法。 篩選比其他參數更有效率,因為提供者會在 Cmdlet 取得物件時套用它們,而不是在擷取對象之後讓 PowerShell 篩選物件。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Include

指定此 Cmdlet 包含在作業中的專案,做為字串陣列。 此參數的值會 限定Path 參數。 輸入路徑專案或模式,例如 "*.txt"。 允許通配符。 Include 參數只有在命令包含項目的內容時有效,例如 C:\Windows\*,其中通配符會指定目錄的內容C:\Windows

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-LiteralPath

指定一或多個位置的路徑。 LiteralPath 的值會與類型完全相同使用。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知PowerShell不要將任何字元解譯為逸出序列。

如需詳細資訊,請參閱 about_Quoting_Rules

Type:String[]
Aliases:PSPath, LP
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

指定要擷取的屬性或屬性名稱。

Type:String[]
Aliases:PSProperty
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Path

指定專案或項目的路徑。 允許通配符。

Type:String[]
Position:0
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:True

輸入

String

您可以使用管線傳送包含此 Cmdlet 路徑的字串。

輸出

PSObject

此 Cmdlet 會針對它取得的每個項目屬性值傳回 物件。 物件類型取決於擷取的屬性值。

備註

PowerShell 包含下列的 Get-ItemPropertyValue別名:

  • 所有平臺:
    • gpv

此 Cmdlet 的設計目的是要處理任何提供者所公開的數據。 若要列出會話中可用的提供者,請執行 Get-PSProvider Cmdlet。 如需詳細資訊,請參閱 about_Providers