get-childitem

AnneW 86 Reputation points
2022-09-06T21:32:56.73+00:00

what does this code mean, esp. -ea and "stop"? thanks

$parentFolders = Get-ChildItem $srcPath -ea "Stop" |
Where-Object {$_.PSIsContainer -eq $true} |
Sort-Object

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-09-07T02:14:26.717+00:00

    In addition to the answer given by @MotoX80 , the Get-ChildItem cmdlet will send a stream of information about all the children of the directory name held in the variable $srcPath into a pipeline. The Where-Object will receive those data and, if any of them represent a directory, send the information into another pipeline. The Sort-Object will receive the data from the second pipeline and sort. it and then send the result to the "Success" stream (becasue there's no other pipeline specified). The sorted information from the Success stream will be stored in the variable "$parentFolders".

    The Where-Object, in this case, is unnecessary and can be replaced by using the Get-ChildItem switch "-Dir". Like this:

    $parentFolders = Get-ChildItem $srcPath -Dir -ErrorAction "Stop" |  
                        Sort-Object  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.