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"

注意

此命令需要有名為 的 PowerShell 磁片磁碟機,其 HKLM: 對應至 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

輸入

String

您可以使用管線傳送包含 路徑的 Get-ItemProperty 字串。

輸出

System.Boolean, System.String, System.DateTime

Get-ItemProperty 會針對它取得的每個專案屬性,傳回 物件。 物件類型取決於所抓取的物件。 例如,在檔案系統磁碟機中,它可能會傳回檔案或資料夾。

備註

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