powershell move-item not working when used in scheduled task RRS feed

  • Question

  • Hi,

    I'm trying to move jpg snapshots from a webcam into daily archive folders via a scheduled powershell script.

    The files have the following naming scheme Snapshot-yyyymmdd-hhmmss.jpg and all files of a single day should be moved into a daily directory named yyyy-mm-dd.

    So I created the following script that works as expected when called directly from the PS command prompt, but not from the windows task scheduler:

        $day_yesterday = (get-date).AddDays(-1).ToString('yyyy-MM-dd')
        $filename = (get-date).AddDays(-1).ToString('yyyyMMdd')
        $source = 'E:\WebCam\jpg\Snapshot-'+ $filename + '-*.jpg'
        if (!(Test-Path -path $destination)){
           New-Item -Path E:\WebCam\jpg\ -Name $day_yesterday -ItemType directory
        move-item $source -Destination $destination

    When called from a scheduled task, the target directory is created, but the move-item commandlet silently fails, the files are not moved but just stay in the source directory.

    The script is running on Windows Server 2008 R2

    Any ideas why this fails or what to change to make it work are appreciated...until then I just run the script manually ever morning...


    Thursday, June 2, 2016 9:21 AM


  • Checking 'Run with highest privileges' in the task settings did the trick - now it works as expected.
    • Marked as answer by T.Braun Thursday, June 2, 2016 10:07 AM
    Thursday, June 2, 2016 10:07 AM