Announcement

Collapse
No announcement yet.

Deleting old files on a remote computer with psexec does not work

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deleting old files on a remote computer with psexec does not work

    Hi,

    I'm running this script, but it does not work.
    I tried to change @path to D:\Logs_Archive\ but it still does not work.

    What am I missing?

    D:\scripts\LogRotationMM>psexec \\192.168.1.2 forfiles -p "D:\Logs_Archive" -s -m *.rar /D -7 /C "cmd /c del @path"

    PsExec v2.2 - Execute processes remotely
    Copyright (C) 2001-2016 Mark Russinovich
    Sysinternals - www.sysinternals.com


    ERROR: Invalid argument/option - '@path'.
    Type "FORFILES /?" for usage.
    forfiles exited on 192.168.1.2 with error code 1.


    Your help is appreciated.

    Thanks


  • #2
    Try this

    forfiles /p "C:\source_folder" /s /m *.* /c "cmd /c Del @path" /d -7

    Comment


    • #3
      Same error:


      ERROR: Invalid argument/option - '@path /d -7 '.

      Comment


      • #4
        What OS are you running?
        Replace @path with @PATH (uppercase)
        There is different versions of forfiles

        Comment


        • #5
          Hi,

          The script is running on Windows Server 2008 R2 (build 7601, SP 1).
          PsExec.exe version 2.2

          I changed to uppercase as you suggested, but it still does not work.

          Comment


          • #6
            Does the script work if you run it locally on the server?

            Maybe try this

            Code:
            psexec \\192.168.1.2 "forfiles -p "D:\Logs_Archive" -s -m *.rar /D -7 /C "cmd /c del @path""

            Comment


            • #7
              Does not work either.
              I tried with psexec and without psexec

              psexec \\192.168.1.2 "forfiles -p "D:\Logs_Archive" -s -m *.rar /D -7 /C "cmd /c del @path"" forfiles -p "D:\Logs_Archive" -s -m *.rar /D -7 /C "cmd /c del @path" Same error

              Comment


              • #8
                So the script fails locally??

                Try this

                Code:
                forfiles -p "D:\Logs_Archive" -s -m *.rar  /C "cmd /c del @file" /D -7

                Comment


                • #9
                  Works

                  Thanks

                  Comment


                  • #10
                    Do you understand why @files works as opposed to @path??

                    Comment

                    Working...
                    X