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

Home Forums Scripting General Scripting Deleting old files on a remote computer with psexec does not work

This topic contains 9 replies, has 3 voices, and was last updated by  BumbleBee 1 year, 8 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts

  • BumbleBee
    Member
    #166938

    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:scriptsLogRotationMM>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 – http://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


    wullieb1
    Moderator
    #245605

    Try this

    forfiles /p “C:source_folder” /s /m *.* /c “cmd /c Del @path” /d –7


    BumbleBee
    Member
    #366815

    Same error:

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

    #348347

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


    BumbleBee
    Member
    #366816

    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.


    wullieb1
    Moderator
    #245606

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

    Maybe try this

    psexec \192.168.1.2 “forfiles -p “D:Logs_Archive” -s -m *.rar /D -7 /C “cmd /c del @path””[/CODE][CODE]psexec \192.168.1.2 “forfiles -p “D:Logs_Archive” -s -m *.rar /D -7 /C “cmd /c del @path””[/CODE]


    BumbleBee
    Member
    #366817

    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


    wullieb1
    Moderator
    #245607

    So the script fails locally??

    Try this

    forfiles -p “D:Logs_Archive” -s -m *.rar /C “cmd /c del @file” /D -7[/CODE][CODE]forfiles -p “D:Logs_Archive” -s -m *.rar /C “cmd /c del @file” /D -7[/CODE]


    BumbleBee
    Member
    #366818

    Works

    Thanks


    wullieb1
    Moderator
    #245610

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

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.