Get-ChildItem
取得一或多個指定位置中的項目和子專案。
語法
Items (預設值)
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint32>]
[-Force]
[-Name]
[-UseTransaction]
[-Attributes <FlagsExpression[FileAttributes]>]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
LiteralItems
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[<CommonParameters>]
Description
Get-ChildItem cmdlet 會取得一或多個指定位置中的項目。 如果項目是容器,它會取得容器內的項目,稱為子項目。 您可以使用 Recurse 參數來取得所有子容器中的專案,並使用 Depth 參數來限制遞歸層級的數目。
Get-ChildItem 不會顯示空的目錄。 當 Get-ChildItem 命令包含 Depth 或 Recurse 參數時,輸出中不會包含空白目錄。
Get-ChildItem Cmdlet 的設計目的是要處理任何提供者所公開的專案。 例如,專案可以是文件系統檔案或目錄、登錄區或證書存儲。 若要列出會話中可用的提供者,請使用 Get-PSProvider 命令。 某些參數僅適用於特定提供者。 如需詳細資訊,請參閱 about_Providers。
範例
範例 1:從檔案系統目錄取得子項目
這個範例會從文件系統目錄取得子項目。 會顯示檔案名和子目錄名稱。 對於空的目錄,命令不會返回任何輸出,並會回到 PowerShell 提示字元。
Get-ChildItem Cmdlet 會使用 Path 參數來指定目錄 C:\Test。
Get-ChildItem 會在 PowerShell 控制台中顯示檔案和目錄。
Get-ChildItem -Path C:\Test
Directory: C:\Test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/15/2019 08:29 Logs
-a---- 2/13/2019 08:55 26 anotherfile.txt
-a---- 2/12/2019 15:40 118014 Command.txt
-a---- 2/1/2019 08:43 183 CreateTestFile.ps1
-ar--- 2/12/2019 14:31 27 ReadOnlyFile.txt
根據預設,Get-ChildItem 會列出模式(屬性)、LastWriteTime、檔案大小(長度),以及專案的 Name。
Mode 屬性中的字母可以解譯如下:
-
l(連結) -
d(目錄) -
a(封存) -
r(唯讀) -
h(隱藏) -
s(系統)
如需模式旗標的詳細資訊,請參閱 about_FileSystem_Provider。
範例 2:取得目錄中的子項目名稱
此範例只會列出目錄中的項目名稱。
Get-ChildItem Cmdlet 會使用 Path 參數來指定目錄 C:\Test。
Name 參數只會從指定的路徑傳回檔案或目錄名稱。 傳回的名稱取決於 Path 參數的值。
Get-ChildItem -Path C:\Test -Name
Logs
anotherfile.txt
Command.txt
CreateTestFile.ps1
ReadOnlyFile.txt
範例 3:獲取目前目錄和子目錄中的子項目
此範例會顯示位於目前目錄及其子目錄中的 .txt 檔案。
Get-ChildItem -Path .\*.txt -Recurse -Force
Directory: C:\Test\Logs\Adirectory
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/12/2019 16:16 20 Afile4.txt
-a-h-- 2/12/2019 15:52 22 hiddenfile.txt
-a---- 2/13/2019 13:26 20 LogFile4.txt
Directory: C:\Test\Logs\Backup
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/12/2019 16:16 20 ATextFile.txt
-a---- 2/12/2019 15:50 20 LogFile3.txt
Directory: C:\Test\Logs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/12/2019 16:16 20 Afile.txt
-a-h-- 2/12/2019 15:52 22 hiddenfile.txt
-a---- 2/13/2019 13:26 20 LogFile1.txt
Directory: C:\Test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/13/2019 08:55 26 anotherfile.txt
-a---- 2/12/2019 15:40 118014 Command.txt
-a-h-- 2/12/2019 15:52 22 hiddenfile.txt
-ar--- 2/12/2019 14:31 27 ReadOnlyFile.txt
Get-ChildItem Cmdlet 會使用 Path 參數來指定 C:\Test\*.txt。
Path 使用星號 (*) 通配符來指定擴展名為 .txt的所有檔案。
Recurse 參數會搜尋 Path 目錄及其子目錄,如 Directory: 標題中所示。
Force 參數會顯示隱藏的檔案,例如具有 hiddenfile.txt模式的 。
範例 4:使用 Include 參數取得子項目
在此範例中,Get-ChildItem 會使用 Include 參數,從 Path 參數所指定的目錄中尋找特定專案。
# When using the -Include parameter, if you don't include an asterisk in the path
# the command returns no output.
Get-ChildItem -Path C:\Test\ -Include *.txt
Get-ChildItem -Path C:\Test\* -Include *.txt
Directory: C:\Test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2/13/2019 08:55 26 anotherfile.txt
-a---- 2/12/2019 15:40 118014 Command.txt
-ar--- 2/12/2019 14:31 27 ReadOnlyFile.txt
Get-ChildItem Cmdlet 會使用 Path 參數來指定目錄 C:\Test。
Path 參數包含尾端星號 (*) 通配符,以指定目錄的內容。
Include 參數會使用星號 (*) 通配符來指定擴展名為 .txt的所有檔案。
使用 Include 參數時,Path 參數需要尾端星號 (*) 通配符來指定目錄的內容。 例如: -Path C:\Test\* 。
- 如果將 Recurse 參數新增至命令中,則在
*參數中的尾端星號()是可選的。 Recurse 參數會從 Path 目錄及其子目錄中取得項目。 例如,-Path C:\Test\ -Recurse -Include *.txt - 如果尾端星號 (
*) 未包含在 Path 參數中,則命令不會傳回任何輸出並返回 PowerShell 提示字元。 例如:-Path C:\Test\。
範例 5:使用 Exclude 參數取得子項目
此範例的輸出會顯示目錄 C:\Test\Logs的內容。 輸出用作其他命令的參考,這些命令使用 Exclude 和 Recurse 參數。
Get-ChildItem -Path C:\Test\Logs
Directory: C:\Test\Logs
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/15/2019 13:21 Adirectory
d----- 2/15/2019 08:28 AnEmptyDirectory
d----- 2/15/2019 13:21 Backup
-a---- 2/12/2019 16:16 20 Afile.txt
-a---- 2/13/2019 13:26 20 LogFile1.txt
-a---- 2/12/2019 16:24 23 systemlog1.log
Get-ChildItem -Path C:\Test\Logs\* -Exclude A*
Directory: C:\Test\Logs
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/15/2019 13:21 Backup
-a---- 2/13/2019 13:26 20 LogFile1.txt
-a---- 2/12/2019 16:24 23 systemlog1.log
Get-ChildItem Cmdlet 會使用 Path 參數來指定目錄 C:\Test\Logs。
Exclude 參數會使用星號 (*) 通配符來指定以 A 或 a 開頭的任何檔案或目錄,都會從輸出中排除。
使用 Exclude 參數時,* 參數中的尾端星號()是可選的。 例如,-Path C:\Test\Logs 或 -Path C:\Test\Logs\*。
- 如果尾端星號 (
*) 未包含在 Path 參數中,則會顯示 Path 參數的內容。 例外狀況是符合 排除 參數值的檔名或子目錄名稱。 - 如果尾端星號 (
*) 包含在 Path 參數中,命令就會遞歸至 Path 參數的子目錄。 例外狀況是符合 排除 參數值的檔名或子目錄名稱。 - 如果 Recurse 參數新增至命令,則遞歸輸出會與 Path 參數是否包含尾端星號 (
*) 相同。
範例 6:從登錄區取得登錄機碼
本範例會從 HKEY_LOCAL_MACHINE\HARDWARE取得所有登錄機碼。
Get-ChildItem 會使用 Path 參數來指定登錄機碼 HKLM:\HARDWARE。 Hive 的路徑和最上層的登錄機碼會顯示在PowerShell控制台中。
如需詳細資訊,請參閱 about_Registry_Provider。
Get-ChildItem -Path HKLM:\HARDWARE
Hive: HKEY_LOCAL_MACHINE\HARDWARE
Name Property
---- --------
ACPI
DESCRIPTION
DEVICEMAP
RESOURCEMAP
UEFI
Get-ChildItem -Path HKLM:\HARDWARE -Exclude D*
Hive: HKEY_LOCAL_MACHINE\HARDWARE
Name Property
---- --------
ACPI
RESOURCEMAP
第一個命令會顯示 HKLM:\HARDWARE 登錄機碼的內容。
Exclude 參數會告知 Get-ChildItem 不要傳回以 D*開頭的任何子機碼。 目前,Exclude 參數僅適用於子機碼,不適用於項目屬性。
範例 7:取得所有程式簽章憑證
此範例會取得 PowerShell Cert: 磁碟驅動器中具有程式碼簽署權限的每個憑證。
Get-ChildItem Cmdlet 會使用 Path 參數來指定具有 Cert: 磁碟驅動器的憑證提供者。
Recurse 參數會搜尋 路徑 所指定的目錄及其子目錄。
CodeSigningCert 參數只會取得具有程式代碼簽署授權單位的憑證。
Get-ChildItem -Path Cert:\* -Recurse -CodeSigningCert
如需憑證提供者和 Cert: 磁碟驅動器的詳細資訊,請參閱 about_Certificate_Provider。
範例 8:使用 Depth 參數取得項目
此範例列出目錄及其子目錄中的項目。 Depth 參數會決定要包含在遞歸中的子目錄層級數目。 空白目錄會從輸出中排除。
Get-ChildItem -Path C:\Parent -Depth 2
Directory: C:\Parent
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/14/2019 10:24 SubDir_Level1
-a---- 2/13/2019 08:55 26 file.txt
Directory: C:\Parent\SubDir_Level1
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/14/2019 10:24 SubDir_Level2
-a---- 2/13/2019 08:55 26 file.txt
Directory: C:\Parent\SubDir_Level1\SubDir_Level2
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/14/2019 10:22 SubDir_Level3
-a---- 2/13/2019 08:55 26 file.txt
Get-ChildItem Cmdlet 會使用 Path 參數來指定 C:\Parent。
Depth 參數會指定兩個遞歸層級。
Get-ChildItem 會顯示 Path 參數所指定的目錄內容,以及子目錄的兩個層級。
範例 9:取得連接點的鏈接目標
Windows 命令殼層中的 dir 命令會顯示檔案系統連接點的目標位置。 在 PowerShell 中,此資訊可從 所傳回之文件系統物件的 Get-ChildItem 屬性取得。
PS D:\> New-Item -ItemType Junction -Name tmp -Target $Env:TEMP
PS D:\> Get-ChildItem | Select-Object Name, *Target
Name Target
---- ------
tmp {C:\Users\user1\AppData\Local\Temp}
範例 10:取得 AppX 重新分析點的連結目標
此範例會嘗試取得 AppX 重新解析點的目標資訊。 Microsoft市集應用程式會在使用者的 AppData 目錄中建立 AppX 重新分析點。
Get-ChildItem ~\AppData\Local\Microsoft\WindowsApps\MicrosoftEdge.exe |
Select-Object Mode, LinkTarget, LinkType, Name
Mode LinkTarget LinkType Name
---- ---------- -------- ----
la--- MicrosoftEdge.exe
目前,Windows 尚未提供一種方式來取得 AppX 重新分析點的目標資訊。 filesystem 物件的 LinkTarget 和 LinkType 属性是空的。
參數
-Attributes
備註
此參數僅適用於 FileSystem 提供者。
取得具有指定屬性的檔案和資料夾。 此參數支援所有屬性,並可讓您指定屬性的複雜組合。
例如,若要取得加密或壓縮的非系統檔案(非目錄),請輸入:
Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed
若要尋找具有常用屬性的檔案和資料夾,請使用 Attributes 參數。 或者,參數 Directory、File、Hidden、ReadOnly和 System。
Attributes 參數支援下列值:
ArchiveCompressedDeviceDirectoryEncryptedHiddenIntegrityStreamNormalNoScrubDataNotContentIndexedOfflineReadOnlyReparsePointSparseFileSystemTemporary
如需這些屬性的描述,請參閱 FileAttributes 列舉。
若要合併屬性,請使用下列運算子:
-
!(非) -
+(和) -
,(OR)
請勿在運算子與其屬性之間使用空格。 逗號後面允許有空格。
針對一般屬性,請使用下列縮寫:
-
D(目錄) -
H(隱藏) -
R(唯讀) -
S(系統)
參數屬性
| 類型: | |
| 預設值: | None |
| 接受的值: | Archive, Compressed, Device, Directory, Encrypted, Hidden, IntegrityStream, Normal, NoScrubData, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, Temporary |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-CodeSigningCert
備註
此參數僅適用於 憑證 提供者。
若要取得其 Code Signing 屬性值中具有 的憑證清單,請使用 CodeSigningCert 參數。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Depth
此參數已在 PowerShell 5.0 中新增,可讓您控制遞歸深度。 根據預設,Get-ChildItem 會顯示父目錄的內容。
Depth 參數會決定遞歸中包含的子目錄層級數目,並顯示內容。
例如,-Depth 2 包含 Path 參數的目錄、子目錄的第一層,以及子目錄的第二層。 根據預設,輸出中會包含目錄名稱和檔名。
備註
Depth 參數與 include 參數搭配使用時沒有作用。 若要解決此問題,請改用 Filter 參數。 PowerShell 6 和更新版本中已修正此問題。
備註
在 PowerShell 或 cmd.exe的 Windows 電腦上,您可以使用 tree.com 命令來顯示目錄結構的圖形檢視。
參數屬性
| 類型: | UInt32 |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Directory
備註
此參數僅適用於 FileSystem 提供者。
若要取得目錄清單,請使用 Directory 參數或 Attributes 參數搭配 Directory 屬性。 您可以將 Recurse 參數與 Directory搭配使用。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 廣告, d |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-DnsName
備註
此參數僅適用於 憑證 提供者。
指定網域名稱或名稱模式,以符合 Cmdlet 取得的憑證 DNSNameList 屬性。 這個參數的值可以是 Unicode 或 ASCII。 Punycode 值會轉換成 Unicode。 允許使用通配符(*)。
此參數已在PowerShell 7.1中重新引入
參數屬性
| 類型: | DnsNameRepresentation |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-DocumentEncryptionCert
備註
此參數僅適用於 憑證 提供者。
若要取得其 Document Encryption 屬性值中具有 的憑證清單,請使用 DocumentEncryptionCert 參數。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Eku
備註
此參數僅適用於 憑證 提供者。
指定文字或文字模式,以符合 Cmdlet 所取得憑證的 EnhancedKeyUsageList 屬性。 允許使用通配符(*)。
EnhancedKeyUsageList 屬性包含 EKU 的友好名稱和 OID 欄位。
此參數已在PowerShell 7.1中重新引入
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Exclude
指定一個或多個字串模式陣列來進行比對,當 Cmdlet 取得子專案時。 輸出中會排除任何相符的專案。 輸入路徑元素或模式,例如 *.txt 或 A*。
可以接受通配符。
* 參數中的尾端星號 () 是選擇性的。 例如,-Path C:\Test\Logs 或 -Path C:\Test\Logs\*。 如果包含尾端星號(*),命令就會遞歸至 Path 參數的子目錄。 如果沒有星號 (*),則會顯示 Path 參數的內容。 範例 5 和附註一節包含更多詳細數據。
Include 和 Exclude 參數可以一起使用。 不過,排除項目會在包含項目之後套用,這可能會影響最終輸出。
備註
Include 和 Exclude 參數與 LiteralPath 參數搭配使用時沒有任何作用。 PowerShell 7 中已修正此問題。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-ExpiringInDays
備註
此參數僅適用於 憑證 提供者。
指定 Cmdlet 應該只傳回在指定天數內或之前到期的憑證。 值為零(0)的情況下會獲得已過期的憑證。
此參數已在PowerShell 7.1中重新引入
參數屬性
| 類型: | Int32 |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-File
備註
此參數僅適用於 FileSystem 提供者。
若要取得檔案清單,請使用 File 參數。 您可以使用 Recurse 參數搭配 File。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | af |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Filter
指定篩選條件,以限定 Path 參數。
FileSystem 提供者是唯一支持篩選的已安裝 PowerShell 提供者。 篩選比其他參數更有效率。 提供者會在 Cmdlet 獲取物件時套用篩選,而不是在擷取物件之後讓 PowerShell 進行篩選。 篩選字串會傳遞至 .NET API 以列舉檔案。 API 僅支援 * 和 ? 通配符。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | 1 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-FollowSymlink
備註
此參數僅適用於 FileSystem 提供者。
根據預設,Get-ChildItem Cmdlet 會顯示遞歸期間找到之目錄的符號連結,但不會遞歸至目錄。 使用 FollowSymlink 參數來搜尋以這些符號連結為目標的目錄。
FollowSymlink 是動態參數,且僅支援 FileSystem 提供者。
此參數是在 PowerShell 6.0 中引進的。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Force
允許 Cmdlet 取得使用者無法存取的項目,例如隱藏或系統檔案。 Force 參數不會覆寫安全性限制。 實作會因提供者而異。 如需詳細資訊,請參閱 about_Providers。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Hidden
備註
此參數僅適用於 FileSystem 提供者。
若要取得僅隱藏的項目,請使用 Hidden 參數或將 Attributes 參數與 Hidden 屬性搭配使用。 根據預設,Get-ChildItem 不會顯示隱藏項目。 使用 Force 參數來取得隱藏的項目。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 啊, h |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Include
指定一個或多個字串模式陣列來進行比對,當 Cmdlet 取得子專案時。 輸出中包含任何相符的項目。 輸入路徑元素或模式,例如 "*.txt"。
允許使用通配符字元。 只有當命令包含項目的內容,例如 時,C:\Windows\* 參數才有效,其中通配符會指定 C:\Windows 目錄的內容。
Include 和 Exclude 參數可以一起使用。 不過,排除項目會在包含項目之後套用,這可能會影響最終輸出。
備註
Include 和 Exclude 參數與 LiteralPath 參數搭配使用時沒有任何作用。 PowerShell 7 中已修正此問題。
備註
Depth 參數與 include 參數搭配使用時沒有作用。 若要解決此問題,請改用 Filter 參數。 PowerShell 6 中已修正此問題。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-LiteralPath
指定通往一個或多個位置的路徑。 LiteralPath 的值會被原樣使用,不做任何更改。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知PowerShell不要將任何字元解譯為逸出序列。
如需詳細資訊,請參閱 about_Quoting_Rules。
備註
Include 和 Exclude 參數與 LiteralPath 參數搭配使用時沒有任何作用。 PowerShell 7 中已修正此問題。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | PSPath |
參數集
LiteralItems
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Name
只取得位置中項目的名稱。 輸出是一個字串物件,可以經由管線傳送至其他命令。 傳回的名稱取決於 Path 參數的值。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Path
指定通往一個或多個位置的路徑。 如果未指定,預設位置是目前目錄 (.)。 接受通配符。 使用 Path 參數搭配 Recurse 參數時,請小心。 如需詳細資訊,請參閱本文的 NOTES 一節。
參數屬性
| 類型: | String[] |
| 預設值: | Current directory |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
Items
| Position: | 0 |
| 必要: | False |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-ReadOnly
備註
此參數僅適用於 FileSystem 提供者。
若要取得唯讀項目,請使用 ReadOnly 參數或 Attributes 參數 ReadOnly 屬性。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 阿拉伯語 |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Recurse
取得指定位置及其所有子項目中的項目。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | s |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-SSLServerAuthentication
備註
此參數僅適用於 憑證 提供者。
若要取得其 Server Authentication 屬性值中具有 的憑證清單,請使用 SSLServerAuthentication 參數。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-System
備註
此參數僅適用於 FileSystem 提供者。
只取得系統檔案和目錄。 若要只取得系統檔案和資料夾,請使用 System 參數或 Attributes 參數 System 屬性。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 如 |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-UseTransaction
在作用中交易中包含 命令。 只有在交易進行中時,此參數才有效。 如需詳細資訊,請參閱 about_Transactions。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | usetx |
參數集
(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: 磁碟驅動器時輸出這些類型。
String
當您使用 Name 參數時,這個 Cmdlet 會以字串的形式傳回物件名稱。
備註
Windows PowerShell 包含下列 Get-ChildItem的別名:
lsdirgci
使用 Path 參數 遞歸行為:
當您搭配 Get-ChildItem -Recurse 參數使用 時,Cmdlet 會搜尋最後一個路徑元件,不論其是否為通配符模式或常值名稱。
- 如果最後一個路徑元件符合目標目錄的現有直接子目錄,Cmdlet 會在比對目錄上執行遞歸列舉。
- 如果最後一個路徑元件不符合目標目錄的現有直接子目錄,Cmdlet 會以遞歸方式搜尋目標目錄階層中符合最後一個路徑元件的專案
當您搭配 Get-ChildItem -Recurse 和 Name 參數使用 時,行為會變更。 此命令會在目標目錄的直接子項目之間搜尋最後一個路徑元件。
- 如果立即子項目之間有相符專案,Cmdlet 會在比對專案上執行遞歸列舉。 通配符比對只會發生在目標目錄的最上層一次。 結果會如同個別傳遞至 LiteralPath 參數一樣進行處理。
- 如果最後一個路徑元件不符合最上層的任何專案,就會發生錯誤。
您應該避免使用 Path 參數搭配 Recurse 參數。 若要獲得最佳結果:
- 使用 LiteralPath 指定目標目錄,以避免觸發最後一個路徑元件的遞歸搜尋。
- 使用 Filter 或 Include 參數來指定應在目標目錄階層的每個層級中搜尋的通配符或常值模式。