I have this Powershell script:
Get-ChildItem –Path "D:\Downloads" -Recurse |
Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item -Recurse -Force -Confirm:$false
If I paste it on a Powershell Window, it work's, but if i try to execute the .ps1 file with the script, a blank Powershell Window open 1 second (because I make that the .ps1 files were opened by Windows Powershell) and next it closes, but the script doesn't work. Only work If I manually open a Powershell Window and paste it the script. The file has privilegies for all the users...
UPDATE:
If I run as bat file, it shows me an error on the code.