RayofCommand
RayofCommand

Reputation: 4244

Using more than 1 Pipeline for

it's my second day of scripting and the week before i just read about powershell. i was given a task to sort out special configurations.zip items from several subfolders which are maybe? TOO big in size. So i searched for folders bigger than 1 KB to prevent the error of having empty folders..

Now i wanted to sort the folders by length with the following operations :

$_.Length -gt 10KB
$_.PSIsContainer -eq $True

QUESTION : How can i have both operations in one line, using 2 Pipelines or even more. For now my script overwrites all the other operations of course.

i found that page which shows that it's possible : http://technet.microsoft.com/en-us/library/ee176927.aspx

but when i simply tried to do both operations after another, my script give me an error. So : HOW to i have to write both operations to work.

Thank you very much!

my script:

$startFolder = "C:\data1"

$colItems = (Get-ChildItem $startFolder -recurse | Measure-Object -property length -sum)

"Mother of all Folders $startFolder -- " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB"

**$colItems = (Get-ChildItem $startFolder -recurse | Where-Object {$_.PSIsContainer -eq $True} )
$colItems = (Get-Childitem $startFolder -recurse | where-Object {$_.Length -gt 1000KB} | Sort-Object Length -descending)**

foreach ($i in $colItems)

{
    $subFolderItems = (Get-ChildItem $i.FullName | Measure-Object -property length -sum)
    $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
}

Upvotes: 0

Views: 113

Answers (1)

Naigel
Naigel

Reputation: 9644

I'm not sure I understood exactly, but you can just use -and operator

$colItems = Get-ChildItem $startFolder -recurse | Where-Object {$_.PSIsContainer -eq $True -and $_.Length -gt 1000KB} | Sort-Object Length -descending)

Upvotes: 1

Related Questions