Get-ChildItem
取得一或多個指定之位置中的項目與子項目。
Syntax
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[<CommonParameters>]
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[<CommonParameters>]
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[-CodeSigningCert]
[-DocumentEncryptionCert]
[-SSLServerAuthentication]
[-DnsName <string>]
[-Eku <string[]>]
[-ExpiringInDays <int>]
[<CommonParameters>]
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[-Attributes <FlagsExpression[FileAttributes]>]
[-FollowSymlink]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint>]
[-Force]
[-Name]
[-Attributes <FlagsExpression[FileAttributes]>]
[-FollowSymlink]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
Description
Cmdlet Get-ChildItem
會取得一或多個指定位置中的專案。 如果項目是容器,它便會取得容器內的項目,稱為子項目。 您可以使用 Recurse 參數來取得所有子容器中的專案,並使用 Depth 參數來限制遞歸的層級數目。
Get-ChildItem
不會顯示空白目錄。 Get-ChildItem
當命令包含 Depth 或 Recurse 參數時,輸出中不會包含空白目錄。
位置會由PowerShell提供者公開 Get-ChildItem
。 位置可以是文件系統目錄、登錄區或證書存儲。 某些參數僅適用於特定提供者。 如需詳細資訊,請參閱 about_Providers。
範例
範例 1:從文件系統目錄取得子專案
這個範例會從文件系統目錄取得子專案。 會顯示檔案名和子目錄名稱。 針對空白位置,命令不會傳回任何輸出,並返回PowerShell提示字元。
Cmdlet Get-ChildItem
會使用 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、檔案大小 (Length) ,以及項目 的名稱 。 Mode 屬性中的字母可以解譯如下:
l
(連結)d
(目錄)a
(封存)r
(唯讀)h
隱藏) (s
(系統)
如需模式旗標的詳細資訊,請參閱 about_Filesystem_Provider。
範例 2:取得目錄中的子項目名稱
本範例只會列出目錄中的項目名稱。
Cmdlet Get-ChildItem
會使用 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
Cmdlet Get-ChildItem
會使用 Path 參數來指定 C:\Test\*.txt
。 路徑 會使用星號 (*
) 通配符來指定擴展名 .txt
為 的所有檔案。 Recurse 參數會搜尋其子目錄的 Path 目錄,如目錄: 標題所示。 Force 參數會顯示隱藏的檔案,例如hiddenfile.txt
具有 h 模式的檔案。
範例 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
Cmdlet Get-ChildItem
會使用 Path 參數來指定目錄 C:\Test
。 Path 參數包含尾端星號 () *
通配符,以指定目錄的內容。
Include 參數會使用星號 () *
通配符來指定擴展名.txt
為 的所有檔案。
使用 Include 參數時, Path 參數需要尾端星號 (*
) 通配符來指定目錄的內容。 例如: -Path C:\Test\*
。
- 如果將 Recurse 參數新增至 命令,Path 參數中的尾端星號 (
*
) 是選擇性的。 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
Cmdlet Get-ChildItem
會使用 Path 參數來指定目錄 C:\Test\Logs
。 Exclude 參數會使用星號 () *
通配符來指定任何開頭A
為 或 的檔案或目錄,或a
從輸出中排除。
使用 Exclude 參數時,Path 參數中的尾端星號 (*
) 是選擇性的。 例如,-Path C:\Test\Logs
或 -Path C:\Test\Logs\*
。
- 如果 Path 參數中不包含尾端星號 (
*
) ,則會顯示 Path 參數的內容。 例外狀況是符合 Exclude 參數值的檔名或子目錄名稱。 - 如果 Path 參數中包含尾端星號 (
*
) ,命令就會遞歸至 Path 參數的子目錄。 例外狀況是符合 Exclude 參數值的檔名或子目錄名稱。 - 如果 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:
磁碟驅動器中具有程式代碼簽署授權單位的每個憑證。
Cmdlet Get-ChildItem
會使用 Path 參數來指定具有磁碟驅動器的 Cert:
憑證提供者。 Recurse 參數會搜尋Path所指定的目錄及其子目錄。 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
Cmdlet Get-ChildItem
會使用 Path 參數來指定 C:\Parent
。 Depth 參數會指定兩個遞歸層級。 Get-ChildItem
會顯示 Path 參數所指定的目錄內容,以及兩個層級的子目錄。
範例 9:取得硬式鏈接資訊
在 PowerShell 6.2 中,已新增替代檢視以取得硬式連結資訊。
Get-ChildItem -Path C:\PathContainingHardLink | Format-Table -View childrenWithHardLink
範例 10:非 Windows 作業系統的輸出
在 Unix 系統上的 PowerShell 7.1 中 Get-ChildItem
,提供類似 Unix 的輸出:
PS> Get-ChildItem /etc/r*
Directory: /etc
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
drwxr-xr-x root wheel 9/30/2019 19:19 128 racoon
-rw-r--r-- root wheel 9/26/2019 18:20 1560 rc.common
-rw-r--r-- root wheel 7/31/2017 17:30 1560 rc.common~previous
-rw-r--r-- root wheel 9/27/2019 20:34 5264 rc.netboot
lrwxr-xr-x root wheel 11/8/2019 15:35 22 resolv.conf -> /private/var/run/resolv.conf
-rw-r--r-- root wheel 10/23/2019 17:41 0 rmtab
-rw-r--r-- root wheel 10/23/2019 17:41 1735 rpc
-rw-r--r-- root wheel 7/25/2017 18:37 1735 rpc~previous
-rw-r--r-- root wheel 10/23/2019 18:42 891 rtadvd.conf
-rw-r--r-- root wheel 8/24/2017 21:54 891 rtadvd.conf~previous
現在屬於輸出一部分的新屬性如下:
- UnixMode 是 Unix 系統上所表示的檔案許可權
- 用戶 是檔案擁有者
- 群組 是群組擁有者
- Size 是 Unix 系統上所表示的檔案或目錄大小
注意
這項功能已從實驗性移至 PowerShell 7.1 中的主流。
範例 11:取得連接點的鏈接目標
dir
Windows 命令殼層中的命令會顯示檔案系統連接點的目標位置。 在 PowerShell 中,此資訊可從所傳回Get-ChildItem
之文件系統物件的 LinkTarget 屬性取得,而且會顯示在默認輸出中。
PS D:\> New-Item -ItemType Junction -Name tmp -Target $env:TEMP
PS D:\> Get-ChildItem | Select-Object name,LinkTarget
Name LinkTarget
---- ----------
tmp C:\Users\user1\AppData\Local\Temp
PS D:\> Get-ChildItem
Directory: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
l---- 12/16/2021 9:29 AM tmp -> C:\Users\user1\AppData\Local\Temp
範例 12:取得 AppX 重新分析點的連結目標
此範例會嘗試取得AppX重新分析點的目標資訊。 Microsoft Store 應用程式會在使用者的 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重新分析點的目標資訊。 文件系統物件的 LinkTarget 和 LinkType 屬性是空的。
參數
-Attributes
注意
此參數僅適用於 FileSystem 提供者。
取得具有指定屬性的檔案和資料夾。 此參數支援所有屬性,可讓您指定複雜的屬性組合。
例如,若要取得已加密或壓縮的非系統檔案 (非目錄),請輸入:
Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed
若要尋找具有常用屬性的檔案和資料夾,請使用 Attributes 參數。 或者, 參數 Directory、 File、 Hidden、 ReadOnly 和 System。
Attributes 參數支援下列屬性:
- 封存
- Compressed
- 裝置
- 目錄
- 已加密
- Hidden
- IntegrityStream
- 一般
- NoScrubData
- NotContentIndexed
- 離線
- ReadOnly
- ReparsePoint
- 疏鬆File
- 系統
- 暫存
如需這些屬性的描述,請參閱 FileAttributes 列舉。
若要合併屬性,請使用下列運算子:
!
(NOT)+
(AND),
(OR)
請勿在運算子與其屬性之間使用空格。 逗號之後接受空格。
針對一般屬性,請使用下列縮寫:
D
(Directory)H
(隱藏)R
(唯讀)S
(系統)
Type: | FlagsExpression<T>[FileAttributes] |
Accepted values: | Archive, Compressed, Device, Directory, Encrypted, Hidden, IntegrityStream, Normal, NoScrubData, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, Temporary |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-CodeSigningCert
注意
此參數僅適用於 憑證 提供者。
若要取得其 EnhancedKeyUsageList 屬性值中具有 Code Signing
的憑證清單,請使用 CodeSigningCert 參數。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Depth
此參數已新增至 PowerShell 5.0,並可讓您控制遞歸的深度。 根據預設, Get-ChildItem
會顯示父目錄的內容。 Depth 參數會決定遞歸中包含的子目錄層級數目,並顯示內容。
例如, -Depth 2
包含 Path 參數的目錄、子目錄的第一層,以及子目錄的第二層。 根據預設,輸出中會包含目錄名稱和檔名。
注意
在 PowerShell 或 cmd.exe的 Windows 電腦上,您可以使用 tree.com 命令來顯示目錄結構的圖形檢視。
Type: | UInt32 |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Directory
注意
此參數僅適用於 FileSystem 提供者。
若要取得目錄清單,請使用 Directory 參數或 Attributes 參數搭配 Directory 屬性。 您可以使用 Recurse 參數搭配 Directory。
Type: | SwitchParameter |
Aliases: | ad |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DnsName
注意
此參數僅適用於 憑證 提供者。
指定功能變數名稱或名稱模式,以符合 Cmdlet 所取得憑證的 DNSNameList 屬性。 這個參數的值可以是 Unicode
或 ASCII
。 Punycode 值會轉換為 Unicode。 允許通配符 (*
) 。
在 PowerShell 7.1 中重新引進此參數
Type: | DnsNameRepresentation |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-DocumentEncryptionCert
注意
此參數僅適用於 憑證 提供者。
若要取得其 EnhancedKeyUsageList 屬性值中具有 Document Encryption
的憑證清單,請使用 DocumentEncryptionCert 參數。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Eku
注意
此參數僅適用於 憑證 提供者。
指定要與 Cmdlet 取得之憑證 的 EnhancedKeyUsageList 屬性相符的文字或文字模式。 允許通配符 (*
) 。 EnhancedKeyUsageList 屬性包含 EKU 的易記名稱和 OID 字段。
在 PowerShell 7.1 中重新引進此參數
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-Exclude
指定要比對之一或多個字串模式的陣列,因為 Cmdlet 會取得子專案。 輸出中會排除任何相符的專案。 輸入路徑專案或模式,例如 *.txt
或 A*
。
(接受萬用字元)。
Path 參數中的尾端星號 (*
) 是選擇性的。 例如,-Path C:\Test\Logs
或 -Path C:\Test\Logs\*
。 如果包含尾端星號 (*
) ,命令會遞歸到 Path 參數的子目錄中。 如果沒有星號 (*
) , 就會顯示Path 參數的內容。 範例 5 和附註一節包含更多詳細數據。
Include 和 Exclude 參數可以一起使用。 不過,排除專案會在包含之後套用,這可能會影響最終輸出。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-ExpiringInDays
注意
此參數僅適用於 憑證 提供者。
指定 Cmdlet 應該只傳回在指定天數內或之前到期的憑證。 值為零 (0
) 取得已過期的憑證。
在 PowerShell 7.1 中重新引進此參數
Type: | Int32 |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-File
注意
此參數僅適用於 FileSystem 提供者。
若要取得檔案清單,請使用 File 參數。 您可以使用 Recurse 參數搭配 File。
Type: | SwitchParameter |
Aliases: | af |
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: | 1 |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-FollowSymlink
注意
此參數僅適用於 FileSystem 提供者。
根據預設, Get-ChildItem
Cmdlet 會顯示遞歸期間所找到目錄的符號連結,但不會遞歸到這些目錄。 使用 FollowSymlink 參數來搜尋以這些符號連結為目標的目錄。 FollowSymlink 是動態參數,且僅在 FileSystem 提供者中受到支援。
此參數是在 PowerShell 6.0 中引進。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
允許 Cmdlet 取得使用者無法存取的專案,例如隱藏或系統檔案。 Force 參數不會覆寫安全性限制。 實作因提供者而異。 如需詳細資訊,請參閱 about_Providers。
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Hidden
注意
此參數僅適用於 FileSystem 提供者。
若要只取得隱藏的專案,請使用 Hidden 參數或 Attributes 參數搭配 Hidden 屬性。 根據預設, Get-ChildItem
不會顯示隱藏的專案。 使用 Force 參數來取得隱藏的專案。
Type: | SwitchParameter |
Aliases: | ah, h |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Include
指定要比對之一或多個字串模式的陣列,因為 Cmdlet 會取得子專案。 輸出中包含任何相符的專案。 輸入路徑元素或模式,例如 "*.txt"
。
允許使用萬用字元。 Include 參數只有在命令包含項目的內容時有效,例如 C:\Windows\*
,其中通配符會指定目錄的內容C:\Windows
。
Include 和 Exclude 參數可以一起使用。 不過,排除專案會在包含之後套用,這可能會影響最終輸出。
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
只取得位置中項目的名稱。 輸出是可將管線向下傳送至其他命令的字串物件。 傳回的名稱會相對於 Path 參數的值。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Path
指定一個或多個位置的路徑。 可使用萬用字元。 預設位置是目前目錄 (.
) 。
Type: | String[] |
Position: | 0 |
Default value: | Current directory |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-ReadOnly
注意
此參數僅適用於 FileSystem 提供者。
若要只取得只讀專案,請使用 ReadOnly 參數或 Attributes 參數 ReadOnly 屬性。
Type: | SwitchParameter |
Aliases: | ar |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Recurse
取得指定之位置中的項目及那些位置中的所有子項目。
Type: | SwitchParameter |
Aliases: | s |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SSLServerAuthentication
注意
此參數僅適用於 憑證 提供者。
若要取得其 EnhancedKeyUsageList 屬性值中具有 Server Authentication
的憑證清單,請使用 SSLServerAuthentication 參數。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-System
注意
此參數僅適用於 FileSystem 提供者。
只取得系統檔案和目錄。 若要只取得系統檔案和資料夾,請使用 System 參數或 Attributes 參數 System 屬性。
Type: | SwitchParameter |
Aliases: | as |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
您可以使用管線將包含路徑的字串傳送至此 Cmdlet。
輸出
Cmdlet 會在存取 Alias:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取 Cert:
磁碟驅動器時輸出這些類型。
Cmdlet 會在存取 Env:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取檔案系統磁碟驅動器時輸出這些類型。
Cmdlet 會在存取 Function:
磁碟驅動器時輸出這些類型。
Cmdlet 會在存取登錄磁碟驅動器時輸出此類型。
Cmdlet 會在存取 Variable:
磁碟驅動器時輸出此類型。
Cmdlet 會在存取 WSMan:
磁碟驅動器時輸出這些類型。
當您使用 Name 參數時,此 Cmdlet 會以字串傳回物件名稱。
備註
PowerShell 包含的下列別名 Get-ChildItem
:
- 所有平台:
dir
,gci
- Windows:
ls
Get-ChildItem
預設不會取得隱藏的專案。 若要取得隱藏的項目,請使用 Force 參數。
此 Get-ChildItem
Cmdlet 的設計目的是要處理任何提供者所公開的數據。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider
。 如需詳細資訊,請參閱 about_Providers。