Powershell 3.5 script converting to 2.0

Can someone help me out here please? I have this powershell script that i use to delete old log files. it works fine on powershell versions 3.5 and higher. Problem is I am now trying to use on a version older and it's a royal pain in the ass trying to figure out the right syntax. Any help would be greatly appreciated. thanks.

-----------------------------script------------------------------------------------------------------
# Delete files older than the $limit.
$limit = (Get-Date).AddDays(-30)
$path = "C:\Program Files\TCI\RetailSuite\HQPM\Logs"

# Delete files older than the $limit.
Get-ChildItem -File $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $limit} | Remove-Item -Force -ea SilentlyContinue
---------------------------end--------------------------------------------------------------------

--first set of errors i get when i run the above. It also complains on "SilentlyContinue

Get-ChildItem : A parameter cannot be found that matches parameter name 'File'.
At C:\Program Files\TCI\RetailSuite\HQPM\HostTran\purgeHqpmLogFiles.ps1:6 char:
20
+ Get-ChildItem -File <<<<  $path -Recurse -Force | Where-Object { !$_.PSIsCont
ainer -and $_.LastWriteTime -lt $limit} | Remove-Item -Force -ea SilentlyContin
ue
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterB
   indingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.GetChildItemCommand
 
Get-ChildItem : A parameter cannot be found that matches parameter name 'File'.
At C:\Program Files\TCI\RetailSuite\HQPM\HostTran\purgeHqpmLogFiles.ps1:6 char:
20
+ Get-ChildItem -File <<<<  $path -Recurse -Force | Where-Object { !$_.PSIsCont
ainer -and $_.LastWriteTime -lt $limit} | Remove-Item -Force -ea SilentlyContin
ue
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterB
   indingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.GetChildItemCommand
Jacob LepleyBusiness Systems Programming AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
# Delete files older than the $limit.
$limit = (Get-Date).AddDays(-30)
$path = "C:\Program Files\TCI\RetailSuite\HQPM\Logs"

# Delete files older than the $limit.
Get-ChildItem $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $limit} | Remove-Item -Force -ea SilentlyContinue 

Open in new window

As coded, the -File has been superfluous, as the Where-Object checked for "not a directory" anyway, which is the purpose of that switch ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Hmmm thanks Qlemo, that worked this time except that was the first thing I tried, and then got an error on the "ea SilentlyContinue". So i removed that as well and got an error that one of the files was currently in use. What can i replace Silentlycontinue with so that if a file is in use it will skip over it?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
No clue why it should complain about -ea SilentlyContinue. It is part of the syntax of Remove-Item even with PS 2.
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Ah. well i went back and looked at the error message and noticed i spelled it wrong. Thank you very much for your help.
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Thank you for the help. Greatly appreciated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.