Get-Item
取得指定位置的項目。
Syntax
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-Stream <string[]>]
[<CommonParameters>]
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-Stream <string[]>]
[<CommonParameters>]
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[<CommonParameters>]
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[<CommonParameters>]
Description
Cmdlet Get-Item
會取得位於指定位置的專案。 除非您使用通配符 () *
來要求專案的所有內容,否則它不會在位置取得項目的內容。
PowerShell 提供者會使用此 Cmdlet 來流覽不同類型的數據存放區。 某些參數僅適用於特定提供者。 如需詳細資訊,請參閱 about_Providers。
範例
範例 1:取得目前的目錄
這個範例會取得目前的目錄。 點 ('.') 代表目前位置的專案, (不是其內容) 。
Get-Item .
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 7/26/2006 10:01 AM ps-test
範例 2:取得目前目錄中的所有專案
本範例會取得目前目錄中的所有專案。 通配符 () *
代表目前專案的所有內容。
Get-Item *
Directory: C:\ps-test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 7/26/2006 9:29 AM Logs
d---- 7/26/2006 9:26 AM Recs
-a--- 7/26/2006 9:28 AM 80 date.csv
-a--- 7/26/2006 10:01 AM 30 filenoext
-a--- 7/26/2006 9:30 AM 11472 process.doc
-a--- 7/14/2006 10:47 AM 30 test.txt
範例 3:取得磁碟驅動器的目前目錄
這個範例會取得磁碟驅動器的 C:
目前目錄。 抓取的物件僅代表目錄,而非其內容。
Get-Item C:
範例 4:取得指定磁碟驅動器中的專案
這個範例會取得磁碟驅動器中的 C:
專案。 通配符 () *
代表容器中的所有專案,而不只是容器。
Get-Item C:\*
在 PowerShell 中,使用單一星號 () *
來取得內容,而不是傳統的 *.*
。 格式會以常值方式解譯,因此 *.*
不會擷取沒有點的目錄或檔名。
範例 5:取得指定目錄中的屬性
這個範例會取得目錄的 C:\Windows
LastAccessTime 屬性。 LastAccessTime 只是文件系統目錄的一個屬性。 若要檢視目錄的所有屬性,請輸入 (Get-Item <directory-name>) | Get-Member
。
(Get-Item C:\Windows).LastAccessTime
範例 6:顯示登錄機碼的內容
此範例顯示 Microsoft.PowerShell 登錄機碼的內容。 您可以使用此 Cmdlet 搭配 PowerShell 登錄提供者來取得登錄機碼和子機碼,但您必須使用 Get-ItemProperty
Cmdlet 來取得登錄值和數據。
Get-Item HKLM:\Software\Microsoft\Powershell\1\Shellids\Microsoft.Powershell\
範例 7:取得目錄中具有排除專案的專案
本範例會取得 Windows 目錄中包含點 () .
但不是以 w*
開頭的專案。只有當路徑包含通配符 (*
) 來指定專案的內容時,這個範例才適用。
Get-Item C:\Windows\*.* -Exclude "w*"
範例 8:取得硬式鏈接資訊
在 PowerShell 6.2 中,已新增替代檢視以取得硬連結資訊。 若要取得硬連結資訊,請將輸出管線傳送至 Format-Table -View childrenWithHardlink
Get-Item C:\Windows\System32\ntoskrnl.exe | Format-Table -view childrenWithHardLink
Directory: C:\Windows\System32
Mode LastWriteTime Length Name
---- ------------- ------ ----
la--- 5/12/2021 7:40 AM 10848576 ntoskrnl.exe
屬性 Mode
會透過 l
中的識別硬式連結 la---
範例 9:非 Windows 作業系統的輸出
在 Unix 系統上的 PowerShell 7.1 中 Get-Item
,Cmdlet 提供類似 Unix 的輸出:
PS> Get-Item /Users
Directory: /
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
drwxr-xr-x root admin 12/20/2019 11:46 192 Users
現在屬於輸出一部分的新屬性如下:
- UnixMode 是 Unix 系統上所表示的檔案許可權
- 用戶 是檔案擁有者
- 群組 是群組擁有者
- Size 是 Unix 系統上所表示的檔案或目錄大小
注意
這項功能已從實驗性移至 PowerShell 7.1 中的主流。
參數
-CodeSigningCert
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
若要取得其 EnhancedKeyUsageList 屬性值中的憑證Code Signing
,請使用 CodeSigningCert 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Credential
注意
任何隨 PowerShell 一起安裝的提供者都不支援此參數。 若要模擬其他使用者,或在執行此 Cmdlet 時提高您的認證,請使用 Invoke-Command。
Type: | PSCredential |
Position: | Named |
Default value: | Current user |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-DnsName
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
指定要與 Cmdlet 所取得憑證 的 DNSNameList 屬性相符的功能變數名稱或名稱模式。 這個參數的值可以是 Unicode
或 ASCII
。 Punycode 值會轉換為 Unicode。 允許通配符 (*
) 。
此參數已在PowerShell 7.1中重新引進
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | DnsNameRepresentation |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-DocumentEncryptionCert
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
若要取得其 EnhancedKeyUsageList 屬性值中具有 Document Encryption
的憑證,請使用 DocumentEncryptionCert 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Eku
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
指定要與 Cmdlet 所取得憑證 的 EnhancedKeyUsageList 屬性相符的文字或文字模式。 允許通配符 (*
) 。 EnhancedKeyUsageList 屬性包含易記名稱和 EKU 的 OID 字段。
此參數已在PowerShell 7.1中重新引進
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-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 |
-ExpiringInDays
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
指定 Cmdlet 應該只傳回在指定天數內或之前到期的憑證。 值為零 (0
) 取得已過期的憑證。
在 PowerShell 7.1 中重新引進此參數
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | Int32 |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Filter
指定篩選條件以限定 Path 參數。 FileSystem 提供者是唯一支持篩選的已安裝 PowerShell 提供者。 篩選比其他參數更有效率。 提供者會在 Cmdlet 取得物件,而不是在擷取對象之後讓 PowerShell 篩選物件時套用篩選。 篩選字串會傳遞至 .NET API 以列舉檔案。 API 僅支援 *
和 ?
通配符。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-Force
表示此 Cmdlet 取得無法存取的專案,例如隱藏的專案。 實作會依提供者而異。 如需詳細資訊,請參閱 about_Providers。 即使使用 Force 參數,Cmdlet 也無法覆寫安全性限制。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-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 |
-Path
指定項目的路徑。 此 Cmdlet 會取得位於指定位置的專案。 允許使用萬用字元。 這是必要參數,但參數名稱 Path 是選擇性的。
使用點 (.
) 來指定目前的位置。 使用通配符 (*
) 來指定目前位置中的所有專案。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-SSLServerAuthentication
這是 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。
若要取得其 EnhancedKeyUsageList 屬性值中的憑證Server Authentication
,請使用 SSLServerAuthentication 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Stream
這是 FileSystem 提供者提供的動態參數。 此參數僅適用於 Windows。
從檔案取得指定的替代數據流。 輸入資料流名稱。 支援萬用字元。 若要取得所有數據流,請使用星號 (*
) 。 此參數在目錄上有效,但請注意,目錄預設沒有數據流。
此參數是在 PowerShell 3.0 中引進。 從 PowerShell 7.2 開始, Get-Item
可以從目錄和檔案取得替代數據流。
如需詳細資訊,請參閱 about_FileSystem_Provider。
Type: | String[] |
Position: | Named |
Default value: | No alternate file streams |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
輸入
您可以使用管線將包含路徑的字串傳送至此 Cmdlet。
輸出
Cmdlet 會在存取 Alias:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取 Cert:
磁碟驅動器時輸出這些類型。
Cmdlet 會在存取 Env:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取檔案系統磁碟驅動器時輸出這些類型。
Cmdlet 會在存取 Function:
磁碟驅動器時輸出這些類型。
Cmdlet 會在存取登錄磁碟驅動器時輸出此類型。
Cmdlet 會在存取 Variable:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取 WSMan:
磁碟驅動器時輸出這些類型。
備註
PowerShell 包含下列的 Get-Item
別名:
- 所有平台:
gi
此 Cmdlet 沒有 Recurse 參數,因為它只會取得專案,而不是其內容。
若要以遞迴方式取得項目的內容,請使用 Get-ChildItem
。
若要瀏覽登錄,請使用此 Cmdlet 來取得登錄機碼,以及 Get-ItemProperty
取得登錄值和數據。 登錄值可視為是登錄機碼的屬性。
此 Cmdlet 是針對與任何提供者公開的資料搭配使用所設計。 若要列出工作階段中可用的提供者,請輸入 Get-PsProvider
。 如需詳細資訊,請參閱 about_Providers。