RandallVillalobos
asked on
Need to delete a windows folder via script for many computers
Experts,
I have a folder called Test.
The location path is: C:\Program Files\Test.
Inside the Test folder I have a whole bunch of programs that I don't need.
I need to delete this "Test" folder in over 100+ computers and I don't want to do it manually.
My question:
1. Is there a bat file or a script that anyone can share that I can run via the network.
( I have network admin rights)
2. I need to delete the folder and all of its content. (no need to backup )
Thank you,
R
I have a folder called Test.
The location path is: C:\Program Files\Test.
Inside the Test folder I have a whole bunch of programs that I don't need.
I need to delete this "Test" folder in over 100+ computers and I don't want to do it manually.
My question:
1. Is there a bat file or a script that anyone can share that I can run via the network.
( I have network admin rights)
2. I need to delete the folder and all of its content. (no need to backup )
Thank you,
R
ASKER
Hi telczj9,
Thanks for your help!
I do have a list of all the computer names, but forgive my lack of knowledge.
I am not following the example all the way.
Lets say that my text files is called "ComputersR.txt" (I'm attaching the text file to verify)
Is the following syntax correct running an exact copy paste?
@echo off
For %%I in (ComputersR.txt) do (
rmdir /q /s \\%%i\c$\progra~1\test
)
ComputersR.txt
Thanks for your help!
I do have a list of all the computer names, but forgive my lack of knowledge.
I am not following the example all the way.
Lets say that my text files is called "ComputersR.txt" (I'm attaching the text file to verify)
Is the following syntax correct running an exact copy paste?
@echo off
For %%I in (ComputersR.txt) do (
rmdir /q /s \\%%i\c$\progra~1\test
)
ComputersR.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome telczj9 , I'm going to open up another question based on this script in case you want to see it.
Thanks a bunch
Thanks a bunch
note that the syntax:
assumes that the account where you will run the batch file has admin access to all those servers.
I enhance the route below to check if the directory exist then remove it, this should limit unexpected messages....
enjoy.
\\computer_name\C$\....
assumes that the account where you will run the batch file has admin access to all those servers.
I enhance the route below to check if the directory exist then remove it, this should limit unexpected messages....
@echo off
FOR /F %%a in (ComputersR.txt) do (
echo Working on: %%a
IF EXIST \\%%a\c$\progra~1\test (
echo Found target directory
rmdir /q /s \\%%a\c$\progra~1\test
) ELSE (
echo did not find target directory
)
)
enjoy.
rmdir /q /s \\computer-name\c$\progra~
The line above and just copy it over and over replacing the computer_name.
Flag /q is for quiet
Flag /s is for removing sub-directories
If you have the computer names in a file you save the time of copy/paste with this in a batch file:
@echo off
For %%I in (file_name_with_computer_n
rmdir /q /s \\%%i\c$\progra~1\test
)
Cheers!