Get-ItemProperty
取得指定項目的屬性。
Syntax
Get-ItemProperty
[-Path] <String[]>
[[-Name] <String[]>]
[-Filter <String>]
[-Include <String[]>]
[-Exclude <String[]>]
[-Credential <PSCredential>]
[<CommonParameters>]
Get-ItemProperty
-LiteralPath <String[]>
[[-Name] <String[]>]
[-Filter <String>]
[-Include <String[]>]
[-Exclude <String[]>]
[-Credential <PSCredential>]
[<CommonParameters>]
Description
Cmdlet Get-ItemProperty
會取得指定項目的屬性。 例如,您可以使用這個 Cmdlet 來取得檔案物件的 LastAccessTime 屬性值。 您也可以使用此 Cmdlet 來檢視登錄專案及其值。
範例
範例 1:取得特定目錄的相關信息
此命令會取得目錄的相關信息 C:\Windows
。
Get-ItemProperty C:\Windows
範例 2:取得特定檔案的屬性
此命令會取得檔案的屬性 C:\Test\Weather.xls
。 結果會以管線傳送至 Format-List
Cmdlet,以將輸出顯示為清單。
Get-ItemProperty C:\Test\Weather.xls | Format-List
範例 3:取得登錄子機碼中登錄專案的值名稱和數據
此命令會取得登錄子機碼中CurrentVersion
登錄專案的值名稱和數據ProgramFilesDir
。 Path 會指定子機碼,而 Name 參數會指定專案的值名稱。
Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name "ProgramFilesDir"
注意
此命令需要有名為的 HKLM:
PowerShell 磁碟驅動器,該磁碟驅動器會對應至 HKEY_LOCAL_MACHINE
登錄的 Hive。
PowerShell 預設會提供具有該名稱和對應的磁碟驅動器。 或者,您可以使用下列替代路徑 (開頭為提供者名稱,後面是兩個冒號) 來指定此登錄子機碼的路徑:
Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
.
範例 4:取得登錄機碼中登錄專案的值名稱和數據
此命令會取得登錄機碼中 PowerShellEngine
登錄專案的值名稱和數據。 結果顯示在下列範例輸出中。
Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine
ApplicationBase : C:\Windows\system32\WindowsPowerShell\v1.0\
ConsoleHostAssemblyName : Microsoft.PowerShell.ConsoleHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=msil
PowerShellVersion : 2.0
RuntimeVersion : v2.0.50727
CTPVersion : 5
PSCompatibleVersion : 1.0,2.0
參數
-Credential
注意
任何與 PowerShell 一起安裝的提供者都不支援此參數。 若要在執行此 Cmdlet 時模擬其他使用者,或提高您的認證,請使用 Invoke-Command。
Type: | PSCredential |
Position: | Named |
Default value: | Current user |
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: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-Path
指定一或多個項目的路徑。 允許使用萬用字元。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
輸入
您可以使用管線將包含路徑的字串傳送至此 Cmdlet。
輸出
這個 Cmdlet 會針對它取得的每個項目屬性傳回 物件。 物件類型取決於所抓取的物件。 例如,在檔案系統磁碟機中,它可能會傳回檔案或資料夾。
備註
PowerShell 包含的下列別名 Get-ItemProperty
:
- 所有平台:
gp
此 Get-ItemProperty
Cmdlet 的設計目的是要處理任何提供者所公開的數據。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider
。 如需詳細資訊,請參閱 about_Providers。