Powershell: Get-Item vs Get-ChildItem

I would like to understand the difference between Get-Itemand Get-ChildItem. If possible with one example.

+4
source share
2 answers

Get-Item
Gets the item at the specified location.

Get-Item .\foo
# returns the item foo

Get-ChildItem
Returns elements and child elements in one or more of the specified locations.

Get-ChildItem .\foo
# returns all of the children within foo

note: Get-ChildItem may also return to child directories

Get-ChildIten .\foo -Recurse
# returns all of the children within foo AND the children of the children

enter image description here

enter image description here

enter image description here

+14
source

Get current directory

Get-Item .

Get all items in the current directory

# use Get-Item
Get-Item *
# or use Get-ChildItem
Get-ChildItem

Get all txt files

# use Get-Item
Get-Item *.txt
# or use Get-ChildItem
Get-ChildItem *.txt

Link:

https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Item?view=powershell-5.1

https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-ChildItem?view=powershell-5.1

+1

Source: https://habr.com/ru/post/1649562/


All Articles