View Only
  • 1.  Deleting Old Reports

    Posted Nov 14, 2017 08:02 AM

    Alright so this isn't related to vmware or powercli, but I have all my scripts output to a temp folder then ftp them to a webserver.  I then have a script run daily to delete any temp file that is older than 60 Days, well just realized sometime ago the script has been failing.  This is the script:

    Get-ChildItem "C:\util\scripts\Temp" -Recurse | where {$_.LastWriteTime -lt (Get-Date).AddDays(-60)} | Remove-Item

    And I have a scheduled task run daily with the highest privileges and a local admin creds. I am now getting a 0x103 error saying its taking to long before I have the task scheduler term the attempt.

    Any ideas?

  • 2.  RE: Deleting Old Reports

    Posted Nov 14, 2017 05:13 PM

    I don't have the answer, but have you ran the script at the PowerShell prompt, without running it through task scheduler?  Maybe the account that it runs under has an issue, or maybe some other scripts are running causing that one to hang. 

  • 3.  RE: Deleting Old Reports

    Posted Nov 15, 2017 03:20 PM

    I moved the time that it runs but still no change.

  • 4.  RE: Deleting Old Reports

    Posted Nov 15, 2017 03:32 PM

    Do you actually need the Recurse switch on the Get-ChildItem?

    Are these reports organised in subfolders under C:\util\scripts\Temp?

    Do these reports have similar file types (.csv, .html...)?

  • 5.  RE: Deleting Old Reports

    Posted Nov 16, 2017 08:46 PM

    There are no subfolders but there are both .csv and .htm files.

  • 6.  RE: Deleting Old Reports
    Best Answer

    Posted Nov 16, 2017 08:57 PM

    A couple of things:

    1. Are you sure there is no interactivity in the script? Did you suppress all warnings?
    2. Perhaps try the following instead of your original code

    $d = (Get-Date).AddDays(-60)

    Get-ChildItem -Path C:\Temp | where{$_.Name -match ".csv$|.htm$" -and $_.LastWriteTime -lt $d} | Remove-Item -Confirm:$false