Powershell - Get-ChildItem Cmdlet



Cmdlet

Get-ChildItem cmdlet 可用於獲取一個或多個特定位置中的專案或子專案。

在以下示例中,我們將看到 Get-ChildItem cmdlet 的實際應用。

示例 1

在此示例中,我們在 D:\temp\test 中有一個名為 test.txt 的檔案,其內容為 "Welcome to TutorialsPoint.Com",而在 D:\temp\test 中有一個名為 test1.txt 的檔案,其內容為 "Hello World!" 和 "Welcome to TutorialsPoint.Com" 這兩行內容。

在變數中獲取檔案詳細資訊。

$A = Get-ChildItem D:\temp\test\*.txt

使用 Format-Wide cmdlet 獲取檔案詳細資訊。

Format-Wide -InputObject $A

輸出

您可以在 PowerShell 控制檯中看到以下輸出。

    Directory: D:\temp\test
test.txt                                         test1.txt           

示例 2

獲取當前目錄中專案的名稱。

在 PowerShell ISE 控制檯中鍵入以下命令

Get-ChildItem -Name

輸出

您可以在 PowerShell 控制檯中看到以下輸出,假定您正在考慮 D:\temp\Test 目錄。

test.csv
test.txt
test.xml
test1.txt
powershell_advanced_cmdlets.htm
廣告
© . All rights reserved.