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登錄專案的值名稱和數據ProgramFilesDirPath 會指定子機碼,而 Name 參數會指定專案的值名稱。

Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name "ProgramFilesDir"

注意

此命令需要有名為 HKLM: 的 PowerShell 磁碟驅動器會對應至 HKEY_LOCAL_MACHINE 登錄區。

根據預設,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

輸入

String

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

輸出

Boolean

String

DateTime

FileInfo

DirectoryInfo

這個 Cmdlet 會針對它取得的每個項目屬性傳回 物件。 物件類型取決於擷取的物件。 例如,在文件系統磁碟驅動器中,它可能會傳回檔案或資料夾。

備註

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

  • 所有平臺:
    • gp

Cmdlet Get-ItemProperty 的設計目的是要處理任何提供者所公開的數據。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider。 如需詳細資訊,請參閱 about_Providers