Issue with task scheduler on schedule (win 2k3 & 2k8)

Answered Issue with task scheduler on schedule (win 2k3 & 2k8)

  • Thursday, January 10, 2013 11:37 AM
     
     

    Running a forfiles script

    forfiles /p "C:\WINDOWS\Temp" /M *.*  /d -1 /c "cmd /c del  @path"

    Its working as expected but I got up with some other challenge here...I created a bach file on win 2k3 box and scheduled it under the task scheduler.
     
    while I am logged into the box, I am getting the below options.
     
    C:\>forfiles /p "C:\WINDOWS\Temp" /M *.*  /d -1 /c "cmd /c del  @path"
     
    C:\WINDOWS\Temp\AeX_{A4597EF2-B2F1-4954-A2FF-A65C393439AF}_1440.tmp
     Access is denied.
     C:\WINDOWS\Temp\KB2487367_10.0.30319\*, Are you sure (Y/N)? y
     C:\WINDOWS\Temp\KB2604121_10.0.30319\*, Are you sure (Y/N)? y
     C:\WINDOWS\Temp\KB2656351_10.0.30319\*, Are you sure (Y/N)? y
     C:\WINDOWS\Temp\KB2656368v2_10.0.30319\*, Are you sure (Y/N)?
     
    when I am not logged onto the server, task scheduler doesn't do anything at all. ensured that the option running the task without logon is checked, unable to understand what else need to be changed.

    ===============================================================

    Running the same forfiles script on windows 2008 R2 box and its behaving the same. Marked the option run the task without the user logon.
     
    Also tried checking with run with highest privileges on the other box in teh task scheduler.

    ===============================================================

    Running the powershell script in the same way to delete files older than 1 day...it works as expected bu on the schedule the task scheduler doesn't do anything.

    $a = Get-ChildItem s:\dbwsrv3\ -recurse

    foreach($x in $a)

       {

           $y = ((Get-Date) - $x.CreationTime).Days

           if ($y -gt 1 -and $x.PsISContainer -ne $True)

               {$x.Delete()}

       }

    created a bat file c:\cleanup.ps1 and schedule, maually running on schedule it doesn't give me any options

    when i run the bat file in windows powershell, gives me the below output

    PS C:\> $a = Get-ChildItem c:\windows\temp\ -recurse
    PS C:\>
    PS C:\> foreach($x in $a)
    >>
    >>     {
    >>
    >>         $y = ((Get-Date) - $x.CreationTime).Days
    >>
    >>         if ($y -gt 1 -and $x.PsISContainer -ne $True)
    >>
    >>             {$x.Delete()}
    >>
    >>     }
    >>
    Exception calling "Delete" with "0" argument(s): "Access to the path 'AeX_{A4597EF2-B2F1-4954-A2FF-A65C393439AF}_1440.t
    mp' is denied."
    At line:5 char:23
    +             {$x.Delete <<<< ()}
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Exception calling "Delete" with "0" argument(s): "Access to the path 'AeX_{A4597EF2-B2F1-4954-A2FF-A65C393439AF}_2532.t
    mp' is denied."
    At line:5 char:23
    +             {$x.Delete <<<< ()}
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Exception calling "Delete" with "0" argument(s): "The process cannot access the file 'FXSAPIDebugLogFile.txt' because i
    t is being used by another process."
    At line:5 char:23
    +             {$x.Delete <<<< ()}
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Exception calling "Delete" with "0" argument(s): "The process cannot access the file 'FXSTIFFDebugLogFile.txt' because
    it is being used by another process."
    At line:5 char:23
    +             {$x.Delete <<<< ()}
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    PS C:\>

    On schedule....it doesn't do anything.

    Any suggestions ????


    • Edited by Admin_Sd Thursday, January 10, 2013 11:38 AM Spell
    •  

All Replies

  • Thursday, January 10, 2013 3:01 PM
     
     Answered

    It appears you do not have permissions to delete those files and that some are in use.

    This is normal for Windows.  You cannot delete files that are in use.

    Always look very closely at the error messages and read them completely.  In PowerShell the messages are very detailed.


    ¯\_(ツ)_/¯

    • Marked As Answer by Admin_Sd Friday, January 25, 2013 12:50 PM
    •  
  • Friday, January 11, 2013 9:35 AM
     
     

    The server is just acting very crazy....I am not seeing anything getting deleted from the path specified while running on schedule and may be all the files are in use and do not have permissions to delete those files according to you !

    If you say that it runs on schedule without deleting the files which are in use. I should be okay with that !

    I shall monitor the files for couple of days and come with a detailed analysis.

    One last question ?? Is there a way to find out the files which are being deleted in powershell running on schedule ?


    Shubankar