0
votes

I have a simple powershell script that I've deployed as a webjob to azure. I want it to delete files older than a time period from a top-level folder "images" (at the same level as the web "site" and Logfiles folders).

Here is the script (xxx is where the name of the site will go):

$limit = (Get-Date).AddMinutes(-1)
$path = "C:\DWASFiles\Sites\xxx\images"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } 
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force

And here is the output:

[07/30/2014 20:28:45 > 4e7488: SYS INFO] Status changed to Initializing [07/30/2014 20:28:45 > 4e7488: SYS INFO] Run script 'deleteold.ps1' with script host - 'PowerShellScriptHost' [07/30/2014 20:28:45 > 4e7488: SYS INFO] Status changed to Running [07/30/2014 20:28:46 > 4e7488: SYS INFO] Status changed to Success

Yet it's not deleting files. It works on my local system. Have I got the wrong path here?

Cheers

1

1 Answers

0
votes

It seems the correct path should be d:\home\images.

But to know for sure go to: https://{sitename}.scm.azurewebsites.net/DebugConsole/ there you can see where the files are located and you can even run your script on your site to make sure it works.