Powershell - Get-ChildItem Cmdlet


Advertisements

Cmdlet

Get-ChildItem cmdlet can be used to get the items or child items in one or more specific locations.

In these examples, we're see the Get-ChildItem cmdlet in action.

Example 1

In this example, first we've a file test.txt in D:\temp\test with content "Welcome to TutorialsPoint.Com" and test1.txt with content "Hello World!" and "Welcome to TutorialsPoint.Com" in two lines.

Get the file details in a variable.

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

Get the file details using Format-Wide cmdlet.

Format-Wide -InputObject $A

Output

You can see following output in PowerShell console.

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

Example 2

Get the names of the items in current directory.

Type the following command in PowerShell ISE Console

Get-ChildItem -Name

Output

You can see following output in PowerShell console consider being in D:\temp\Test directory.

test.csv
test.txt
test.xml
test1.txt
powershell_advanced_cmdlets.htm
Advertisements