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 參數時所指定之屬性的目前值,其位於您使用 Path 或 LiteralPath 參數指定的路徑中。
範例
範例 1︰取得 ProductID 屬性的值
此命令會取得 Windows 登錄提供者中 “\SOFTWARE\Microsoft\Windows NT\CurrentVersion” 物件的 ProductID 屬性值。
Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ProductID
94253-50000-11141-AA785
範例 2︰取得檔案或資料夾的上次寫入時間
此命令會從C:\Program Files\PowerShell
在 FileSystem 提供者中工作的資料夾取得 LastWriteTime 屬性的值,或上次變更檔案或資料夾的時間。
Get-ItemPropertyValue -Path 'C:\Program Files\PowerShell' -Name LastWriteTime
Wednesday, September 3, 2014 2:53:22 PM
範例 3︰取得檔案或資料夾的多個屬性值
此命令會取得資料夾的 LastWriteTime、CreationTime 和 Root 屬性的值。 屬性值會以您指定屬性名稱的順序傳回。
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 |
輸入
您可以使用管線將包含路徑的字串傳送至此 Cmdlet。
輸出
此 Cmdlet 對於取得的每個項目屬性值會傳回一個物件。 物件類型取決於所抓取的屬性值。
備註
PowerShell 包含下列的 Get-ItemPropertyValue
別名:
- 所有平台:
gpv
此 Cmdlet 是針對與任何提供者公開的資料搭配使用所設計。 若要列出會話中可用的提供者,請執行 Get-PSProvider
Cmdlet。 如需詳細資訊,請參閱 about_Providers。