Link to home
Create AccountLog in
Avatar of MOQINFRA
MOQINFRA

asked on

Script needed to delete a folder

Need  script to delete a folder forcefully from all machines.

this folder can be on any of the drives that a computer has .

E.g the Folder1  may be on C: on server1 but on D: on Server 2

The requirement is to look for this folder where it is and delete it except if it on E:
Avatar of Bill Prew
Bill Prew

Will you have a file listing all computers to remove the folder from that the VBS script will read?

You want to remove the folder even if it is not empty I assume?

~bp
Avatar of MOQINFRA

ASKER

Yes want to remove the folder even if it is empty.

I will send the script out to all computers  using SCCM or Group Policy or psexec
And just to clarify, will the folder always be in the root of the drive(s) we want to remove it from, or could it be a subfolder beneath any other subfolders on the drive (adds more processing time naturally)?

~bp
The folder is on the root of the drive
Any update
Sorry, been tied up on a few other things, but will work this today.

~bp
Will you be running this with Admin privs on the servers?

~bp
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I changed the folder to C:\Tmp

And while i ran this , it returned all the folders on the computer
Not sure what you mean.  Did you change:

strDeleteFolder = "Temp"

to:

strDeleteFolder = "Tmp"

or:

strDeleteFolder = "C:\Tmp"

or something else?  The last one won't work, you only want the name of the folder you are looking for there, not the drive letter, since we are searching many drives.

Also, notice the:

' Set logging level (0=none, 1=basic, 2=full)
intLogging = 2

near the top.  With that set at 2, you will see all folders that the script checks, that's for debugging.  You can change it to 1 to reduce the debug displays, or right to 0 to not display anything except the folders it finds to delete.

~bp
Thank you