0

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"
}

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.