共用方式為


Get-Item

取得位於指定位置的項目。

語法

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

Get-Item cmdlet 會取得位於指定位置的項目。 除非您使用通配符(*)來請求項目的所有內容,否則無法取得該位置的項目內容。

PowerShell 提供者會使用此 Cmdlet 來流覽不同類型的數據存放區。

範例

範例 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 登錄機碼的內容。 您可以使用此 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。

若要取得其 Code Signing 屬性值中具有 的憑證,請使用 CodeSigningCert 參數。

如需詳細資訊,請參閱 about_Certificate_Provider

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Credential

注意

任何與 PowerShell 一起安裝的提供者都不支援此參數。 若要模擬其他使用者,或在執行此 Cmdlet 時提升您的認證,請使用 Invoke-Command

類型:PSCredential
Position:Named
預設值:Current user
必要:False
接受管線輸入:True
接受萬用字元:False

-DnsName

這是由 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。

指定網域名稱或名稱模式,以符合 Cmdlet 取得的憑證 DNSNameList 屬性。 這個參數的值可以是 UnicodeASCII。 Punycode 值會轉換成 Unicode。 可以使用通配符(*)。

此參數已在PowerShell 7.1中重新引入

如需詳細資訊,請參閱 about_Certificate_Provider

類型:DnsNameRepresentation
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:True

-DocumentEncryptionCert

這是由 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。

若要取得 Document Encryption 屬性值中具有 的憑證,請使用 DocumentEncryptionCert 參數。

如需詳細資訊,請參閱 about_Certificate_Provider

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Eku

這是由 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。

指定文字或文字模式,以符合 Cmdlet 所取得憑證的 EnhancedKeyUsageList 屬性。 可以使用通配符(*)。 EnhancedKeyUsageList 屬性包含 EKU 的易記名稱和 OID 字段。

此參數已在PowerShell 7.1中重新引入

如需詳細資訊,請參閱 about_Certificate_Provider

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:True

-Exclude

指定一個或多個在此作業中被排除的專案,以字串陣列形式表示。 此參數的值會限定 path 參數。 輸入路徑元素或模式,例如 *.txt。 可以使用通配符。 只有在命令包含項目的內容,例如 時,C:\Windows\* 參數才有效,其中通配符會指定 C:\Windows 目錄的內容。

類型:String[]
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:True

-ExpiringInDays

這是由 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。

指定 Cmdlet 應該只傳回在指定天數內或之前到期的憑證。 值為零(0)的情況下會獲得已過期的憑證。

此參數已在PowerShell 7.1中重新引入

如需詳細資訊,請參閱 about_Certificate_Provider

類型:Int32
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Filter

指定篩選條件,以限定 Path 參數。 FileSystem 提供者是唯一支持篩選的已安裝 PowerShell 提供者。 篩選比其他參數更有效率。 提供者會在 Cmdlet 取得物件時套用篩選,而不是在擷取物件之後才讓 PowerShell 進行篩選。 篩選字串會傳遞至 .NET API 以列舉檔案。 API 僅支援 *? 通配符。

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:True

-Force

表示此 Cmdlet 能取得其他方式無法存取的專案,例如隱藏的專案。 實作會因提供者而異。 如需詳細資訊,請參閱 about_Providers。 即使使用 Force 參數,Cmdlet 也無法覆寫安全性限制。

類型:SwitchParameter
Position:Named
預設值:False
必要:False
接受管線輸入:False
接受萬用字元:False

-Include

指定一個或多個此 Cmdlet 在作業中要包含的項目,做為字串陣列。 此參數的值會限定 path 參數。 輸入路徑元素或模式,例如 *.txt。 可以使用通配符。 只有當命令包含項目的內容,例如 時,C:\Windows\* 參數才有效,其中通配符會指定 C:\Windows 目錄的內容。

類型:String[]
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:True

-LiteralPath

指定一條或多條位置的路徑。 LiteralPath 的值會完全按照輸入的樣式使用。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知PowerShell不要將任何字元解譯為逸出序列。

如需詳細資訊,請參閱 about_Quoting_Rules

類型:String[]
別名:PSPath, LP
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-Path

指定項目的路徑。 此 Cmdlet 會在指定的位置取得專案。 可以使用通配符。 這是必要參數,但路徑 參數名稱是選擇性的。

使用點 (.) 來指定目前的位置。 使用通配符(*)來指定目前位置中的所有項目。

類型:String[]
Position:0
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:True

-SSLServerAuthentication

這是由 憑證 提供者提供的動態參數。 此參數和 憑證 提供者僅適用於 Windows。

若要取得在其 Server Authentication 屬性值中具有 的憑證,請使用 SSLServerAuthentication 參數。

如需詳細資訊,請參閱 about_Certificate_Provider

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Stream

這是 FileSystem 提供者所提供的動態參數。 此參數僅適用於 Windows。

從檔案取得指定的替代數據流。 輸入數據流名稱。 支援通配符。 若要取得所有數據流,請使用星號 (*)。 此參數在目錄上有效,但請注意,目錄預設沒有數據流。

此參數是在 PowerShell 3.0 中引進的。 從 PowerShell 7.2 開始,Get-Item 可以從目錄和檔案取得替代數據流。

如需詳細資訊,請參閱 about_FileSystem_Provider

類型:String[]
Position:Named
預設值:No alternate file streams
必要:False
接受管線輸入:False
接受萬用字元:True

輸入

String

您可以透過管道傳送包含路徑的字串至此 Cmdlet。

輸出

AliasInfo

Cmdlet 會在存取 Alias: 磁碟驅動器時輸出此類型。

X509StoreLocation

X509Store

X509Certificate2

Cmdlet 會在存取 Cert: 磁碟驅動器時輸出這些類型。

DictionaryEntry

Cmdlet 會在存取 Env: 磁碟驅動器時輸出此類型。

DirectoryInfo

FileInfo

Cmdlet 會在存取檔案系統磁碟驅動器時輸出這些類型。

FunctionInfo

FilterInfo

Cmdlet 會在存取 Function: 磁碟驅動器時輸出這些類型。

RegistryKey

Cmdlet 會在存取登錄磁碟驅動器時輸出此類型。

PSVariable

Cmdlet 會在存取 Variable: 磁碟驅動器時輸出此類型。

WSManConfigContainerElement

WSManConfigLeafElement

Cmdlet 會在存取 WSMan: 磁碟驅動器時輸出這些類型。

備註

PowerShell 包含下列 Get-Item別名:

  • 所有平臺:
    • gi

此 Cmdlet 沒有 Recurse 參數,因為它只會取得項目,而不是其內容。 若要以遞歸方式取得項目的內容,請使用 Get-ChildItem

若要瀏覽登錄,請使用此 Cmdlet 來取得登錄機碼和 Get-ItemProperty,以取得登錄值和數據。 登錄值會被視為登錄機碼的屬性。

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