Need Help writing a PowerShell Script. Redirecting Files based on Size.

by Jul 20, 2011

Hello, I am currently attempting to write a script that will Redirect Files, from a specified path, to a different path based on size. Ex. I need to bring up, perhaps, a recursive tree of say C:Temp and if any file in that directory has a filesize of (Let's use) 50KB or greater, warn the user and then redirect that File to a different directory path. (C:LargeFiles) So far I have some basic PowerShell Code to get the filesize: $filepath="C:Temp" Get-ChildItem $filepath | ForEach-Object {Write-Host $,==> ($_.Length/1KB).tostring("0.00")KB} This retrieves the file name and filesize in KB's of the path C:temp and displays it. I was thinking that an "IF" statement could be used to return the files -gt "50.00"KB and then warn the user in a messageBox that the path has Large files, they will be redirected to C:LargeFiles and then perhaps use the Move-Item cmdlet to move certain files to the new directory. Any help getting me started in the right direction with the IF statement or perhaps a better way of accomplishing this would be greatly appreciated. Thank You. TW