Scheduled powershell script won't run on W2003SP2

Answered Scheduled powershell script won't run on W2003SP2

  • Wednesday, July 04, 2012 12:21 PM
     
     

    I have a scheduled task on Windows server 2003 SP2 that points to a powershell script. The problem is that the scheduled task starts a powershell console window (title has svchost.exe) but does not run the script. What's more when I add the argument -noexit so that the powershell windows stays open and manually type the full path to the script in it still does nothing. When I run a 'whoami' command it is using the correct domain admin account that was specified and has permissions to run the script. The script will run if a normal powershell window is opened and you type the full path to the script in. The command in the schedtask run box is below and I have already tried all sorts of variations on it:

    C:\WINNT\system32\WINDOW~2\v1.0\powershell.exe -noprofile -noexit "&{d:\gpobackups\PurgeGPOBackups.ps1}"

    # Script to purge all GPO folders older than 365 days
    $GPOBKPATH = "D:\GPOBackups"

    Get-ChildItem $GPOBKPATH | where-object {$_.CreationTime -le (Get-Date).adddays(-365) `
     -And $_.PSisContainer -eq 'True'} | remove-item -recurse -force

    I have even tried pointing the scheduled task at a batch file that calls the powershell script but I get the same problem. Execution policy is set to unrestricted.

    Can anyone help or advise? Thank you.


    • Edited by Stu-NI Wednesday, July 04, 2012 12:22 PM
    •  

All Replies

  • Wednesday, July 04, 2012 12:52 PM
     
     Answered
    Resolved - I have just noticed that the script was running successfully when scheduled but because it no longer found any folders created more than 365 days ago it looked as if it wasn't doing anything. My bad.
    • Marked As Answer by Stu-NI Wednesday, July 04, 2012 12:52 PM
    •