Problem when running in schedule task

Welcome Forums General PowerShell Q&A Problem when running in schedule task

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5361

    Points: 0
    Rank: Member

    by habs3 at 2012-12-18 05:45:42

    Good morning,

    When i try to run the following script in a scheduled task the zipping part does not work. If i run it outside of the schedule task it works great. Is it because the script is running an EXE? Ideas to make it work?

    Get-childitem D:\AA-Perfwiz-Data\*.zip | where { ((get-date)-$_.LastWriteTime).days -ge 30} | remove-item -force
    $DTE = Get-Date -Format MMddyyy
    $Itm = get-childitem -path D:\AA-Perfwiz-Data | where-object {($_.Length -gt "536000000") -and ($_.Extension -eq ".blg")} | select-object BaseName
    foreach ($BName in $Itm)
    $BName.BaseName | out-file D:\AA-Perfwiz-Data\files_beingzipped$dte.txt -append
    $PerfData = get-content -path D:\AA-Perfwiz-Data\files_beingzipped$dte.txt
    foreach ($DataItem in $PerfData)
    & D:\AA-Perfwiz-Data\7z.exe a -tzip "$" "$DataItem.blg"

    $ToDel = get-content D:\AA-Perfwiz-Data\files_beingzipped$dte.txt
    foreach ($Perf in $ToDel)
    "$Perf.blg" | remove-item
    remove-item -path D:\AA-Perfwiz-Data\files_beingzipped$dte.txt -force

    by robertskinner at 2012-12-18 08:10:44

    I assume you are running the script under the same credentials both times? What Attributes are you using in the scheduled task when calling PowerShell as well as the start-in in directory? I just did a simple test, with just calling the 7zip and it created a files for me. Unless there is something I am missing in your code, others can comment, I don't have the time to test that right now.

    by habs3 at 2012-12-18 10:27:51

    I am using the directory that all the files are in and i tried using my domain admin account as well as the local admin account.

    by robertskinner at 2012-12-18 13:12:16

    Why not do a transcript dump to capture everything to see where problems may exist.

    Start-Transcript "c:\temp\test.txt"

The topic ‘Problem when running in schedule task’ is closed to new replies.