none
How can "multiple folders/files" be deleted in ONE PSEXEC COMMAND LINE RRS feed

  • Question

  • I can delete remote folders/files via bat command with psexec (below) but; 
    It takes a little time because of the 9 different folders. Maybe, looping of txt file can be used for different folders.

    So how we can delete multiple folders in ONE PSEXEC COMMAND LINE?

    Here my working code but it does its job in 9 steps :(
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\1*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\2*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\3*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\4*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\5*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\6*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\7*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\8*.*") do rd /s /q "%%a""
    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\9*.*") do rd /s /q "%%a""

    \_(ツ)_/ twitter.com/serdaruzun

    Friday, July 18, 2014 7:21 AM

Answers

  • I think it is:

    psexec \\%PC% cmd /c "for /l %%n in (1;1;9) do for /d %%a in ("c:\Users\%%n*.*") do rd /s /q "%%a""


    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Friday, July 18, 2014 9:25 AM
    Friday, July 18, 2014 9:25 AM
  • This worked, too :)

    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\1*.*","c:\Users\2*.*","c:\Users\3*.*","c:\Users\4*.*","c:\Users\5*.*","c:\Users\6*.*","c:\Users\7*.*","c:\Users\8*.*","c:\Users\9*.*") do rd /s /q "%%a""


    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Monday, September 8, 2014 9:37 AM
    Monday, September 8, 2014 9:37 AM

All replies

  • You need to post PsExec questions in the PsExec forum.  PsExec is  utility and not a script.

    Post in the forum for the utility.

    You can also just read the documentation carefully fro examples of how to use this.


    ¯\_(ツ)_/¯

    Friday, July 18, 2014 9:00 AM
  • If you move my post to PsExec forum I will be glad

    \_(ツ)_/ twitter.com/serdaruzun

    Friday, July 18, 2014 9:03 AM
  • Create a local batch file containing the "rd" commands, then use the -c option to copy it to the target machine and execute it there.

     -c        Copy the specified program to the remote system for
                execution. If you omit this option the application
                must be in the system path on the remote system.

    • Marked as answer by serdaruzun Friday, July 18, 2014 9:05 AM
    • Unmarked as answer by serdaruzun Friday, July 18, 2014 9:05 AM
    Friday, July 18, 2014 9:03 AM
  • Friday, July 18, 2014 9:04 AM
  • Create a local batch file containing the "rd" commands, then use the -c option to copy it to the target machine and execute it there.

     -c        Copy the specified program to the remote system for
                execution. If you omit this option the application
                must be in the system path on the remote system.

    Please read again my question :)

    \_(ツ)_/ twitter.com/serdaruzun

    Friday, July 18, 2014 9:05 AM
  • http://forum.sysinternals.com/


    ¯\_(ツ)_/¯

    Thank you :) I asked also there :)

    Jrv yoare a good lecturer


    \_(ツ)_/ twitter.com/serdaruzun

    Friday, July 18, 2014 9:14 AM
  • I think it is:

    psexec \\%PC% cmd /c "for /l %%n in (1;1;9) do for /d %%a in ("c:\Users\%%n*.*") do rd /s /q "%%a""


    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Friday, July 18, 2014 9:25 AM
    Friday, July 18, 2014 9:25 AM
  • Your answer is not what the documentation reads. Please post in the correct forum.

    Fred was nice enough to copy the help for you but you have not beennice enough to red it.

    Please read carefully and look up the word "copy" in a dictionary to see what the instructions mean whenthey say "COPY A PROGRAM"


    ¯\_(ツ)_/¯

    COPY A PROGRAM is very clear...

    There is no any connection with my question.....

    You dont have to be polemic


    \_(ツ)_/ twitter.com/serdaruzun

    Friday, July 18, 2014 1:40 PM
  • I oppologize.  I didn't read you commdline correctly.

    That will partial work but is a strange method.

    What Fred was trying to show you was how to send a batch remotely.

    For complex issues with PsExec please post in the appropriate forum.


    ¯\_(ツ)_/¯

    Friday, July 18, 2014 2:06 PM
  • This worked, too :)

    psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\1*.*","c:\Users\2*.*","c:\Users\3*.*","c:\Users\4*.*","c:\Users\5*.*","c:\Users\6*.*","c:\Users\7*.*","c:\Users\8*.*","c:\Users\9*.*") do rd /s /q "%%a""


    \_(ツ)_/ twitter.com/serdaruzun

    • Marked as answer by serdaruzun Monday, September 8, 2014 9:37 AM
    Monday, September 8, 2014 9:37 AM