Get-Item
在指定地點取得物品。
語法
Path (Default) - FileSystem provider
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-Stream <string[]>]
[<CommonParameters>]
LiteralPath - FileSystem provider
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-Stream <string[]>]
[<CommonParameters>]
Path (Default) - Certificate provider
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
LiteralPath - Certificate provider
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
Path (Default) - All providers
Get-Item
[-Path] <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[<CommonParameters>]
LiteralPath - All providers
Get-Item
-LiteralPath <string[]>
[-Filter <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Force]
[-Credential <pscredential>]
[<CommonParameters>]
Description
指令長在 Get-Item 指定位置取得該物品。 除非你用萬用字元(*)請求該物品的所有內容,否則它不會在該地點取得物品的內容。
此 cmdlet 被 PowerShell 提供者用來瀏覽不同類型的資料儲存。
範例
範例 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 只是檔案系統目錄的一個屬性。 要查看目錄的所有屬性,請輸入 (Get-Item <directory-name>) | Get-Member。
(Get-Item C:\Windows).LastAccessTime
範例 6:顯示登錄檔金鑰的內容
此範例顯示 Microsoft 的內容。PowerShell registry key. 你可以用這個 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屬性透過 in 來識別硬連結lla---
範例 9:非 Windows 作業系統的輸出
在 Unix 系統的 PowerShell 7.1 中,cmdlet Get-Item 提供類 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 系統上所代表的檔案或目錄大小
Note
此功能已從實驗性移至 PowerShell 7.1 中的主流。
參數
-CodeSigningCert
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
要取得憑證中包含 Code SigningEnhancedKeyUsageList 屬性值的憑證,請使用 CodeSigningCert 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Credential
Note
任何與 PowerShell 一起安裝的提供者都不支援此參數。 若要模擬其他使用者,或在執行此 Cmdlet 時提升您的認證,請使用 Invoke-Command。
參數屬性
| 類型: | PSCredential |
| 預設值: | Current user |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-DnsName
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
指定網域名稱或名稱模式,以符合 Cmdlet 取得的憑證 DNSNameList 屬性。 這個參數的值可以是 Unicode 或 ASCII。 Punycode 值會轉換成 Unicode。 允許使用通配符(*)。
此參數已在PowerShell 7.1中重新引入
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | DnsNameRepresentation |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-DocumentEncryptionCert
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
要取得憑證中包含 Document EncryptionEnhancedKeyUsageList 屬性值的憑證,請使用 DocumentEncryptionCert 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Eku
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
指定文字或文字模式,以符合 Cmdlet 所取得憑證的 EnhancedKeyUsageList 屬性。 允許使用通配符(*)。
EnhancedKeyUsageList 屬性包含 EKU 的友好名稱和 OID 欄位。
此參數已在PowerShell 7.1中重新引入
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Exclude
指定要在此 Cmdlet 作業中排除的項目或多項,並以字串陣列形式表示。 此參數的值對 路徑 參數進行限定。 輸入路徑元素或模式,例如 *.txt。 允許使用通配符字元。 只有在命令包含項目的內容,例如 時,C:\Windows\* 參數才有效,其中通配符會指定 C:\Windows 目錄的內容。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-ExpiringInDays
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
指定 Cmdlet 應該只傳回在指定天數內或之前到期的憑證。 值為零(0)的情況下會獲得已過期的憑證。
此參數已在PowerShell 7.1中重新引入
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | Int32 |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Filter
指定篩選條件,以限定 Path 參數。
FileSystem 提供者是唯一支持篩選的已安裝 PowerShell 提供者。 篩選比其他參數更有效率。 提供者會在 Cmdlet 獲取物件時套用篩選,而不是在擷取物件之後讓 PowerShell 進行篩選。 篩選字串會傳遞至 .NET API 以列舉檔案。 API 僅支援 * 和 ? 通配符。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Force
表示此指令長能取得無法取得的物品,例如隱藏物品。 實作會因提供者而異。 如需詳細資訊,請參閱 about_Providers。 即使使用 Force 參數,Cmdlet 也無法覆蓋安全性限制。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Include
指定此 Cmdlet 在操作中包含的一個或多個專案,這些專案是以字串陣列的形式表示。 此參數的值對 路徑 參數進行限定。 輸入路徑元素或模式,例如 *.txt。 允許使用通配符字元。 只有當命令包含項目的內容,例如 時,C:\Windows\* 參數才有效,其中通配符會指定 C:\Windows 目錄的內容。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-LiteralPath
指定通往一個或多個位置的路徑。 LiteralPath 的值會被原樣使用,不做任何更改。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知PowerShell不要將任何字元解譯為逸出序列。
如需詳細資訊,請參閱 about_Quoting_Rules。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | PSPath, LP |
參數集
LiteralPath
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Path
指定通往某個項目的路徑。 這個指令子在指定位置取得物品。 允許使用通配符字元。 此參數為必填條件,但參數名稱 Path 為可選。
用點(.)來指定目前的位置。 使用萬用字元(*)來指定目前位置的所有物品。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
Path
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-SSLServerAuthentication
這是由 憑證 提供者提供的動態參數。 此參數及 Certificate 提供者僅在 Windows 上提供。
要取得憑證中包含 Server AuthenticationEnhancedKeyUsageList 屬性值的憑證,請使用 SSLServerAuthentication 參數。
如需詳細資訊,請參閱 about_Certificate_Provider。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Stream
這是 FileSystem 提供者所提供的動態參數。 此參數僅適用於 Windows。
從檔案取得指定的替代資料流。 輸入數據流名稱。 支援通配符。 要取得所有串流,請使用星號(*)。 此參數適用於目錄,但目錄預設沒有資料串流。
此參數是在 PowerShell 3.0 中引進的。 從 PowerShell 7.2 起,可以 Get-Item 從目錄和檔案取得替代資料流。
如需詳細資訊,請參閱 about_FileSystem_Provider。
參數屬性
| 類型: | String[] |
| 預設值: | No alternate file streams |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
CommonParameters
此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。
輸入
String
您可以傳送包含路徑的字串到此 Cmdlet。
輸出
AliasInfo
Cmdlet 會在存取 Alias: 磁碟驅動器時輸出此類型。
X509StoreLocation
X509Store
X509Certificate2
Cmdlet 會在存取 Cert: 磁碟驅動器時輸出這些類型。
DictionaryEntry
Cmdlet 會在存取 Env: 磁碟驅動器時輸出此類型。
DirectoryInfo
FileInfo
當 cmdlet 存取 FileSystem 磁碟時會輸出這些類型。
FunctionInfo
FilterInfo
Cmdlet 會在存取 Function: 磁碟驅動器時輸出這些類型。
RegistryKey
Cmdlet 會在存取登錄磁碟驅動器時輸出此類型。
PSVariable
Cmdlet 會在存取 Variable: 磁碟驅動器時輸出此類型。
WSManConfigContainerElement
WSManConfigLeafElement
Cmdlet 會在存取 WSMan: 磁碟驅動器時輸出這些類型。
備註
PowerShell 包含下列 Get-Item的別名:
- 所有平臺:
gi
這個 cmdlet 沒有遞 迴 參數,因為它只取得一個項目,而非其內容。
要遞迴取得某個項目的內容,請使用 Get-ChildItem。
要在登錄檔中導航,請使用此 cmdlet 取得登錄檔金鑰,以及 Get-ItemProperty 取得登錄檔值與資料。 登錄檔值被視為登錄鍵的屬性。
此 Cmdlet 的設計目的是要處理任何提供者所公開的數據。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider。 如需詳細資訊,請參閱 about_Providers。