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.