Jump to content

Recommended Posts

Posted

Hi Guys,

 

bit of help needed .... Pretty Pwease

 

Back into a windows Enviroment after being in *Nix / Apple enviromentt for years ...

 

One of the problems we are having is the Network recyler folder is filling some 200 Servers up with space - Folder redirect is a mess and GPO cannot be touched - Else i would of just cleared this up ...

 

What im after is a VBSCRIPT i can just run against the Home drives of network user to erase all the recycler data in one go

 

so

 

\\servername\home\username\recycler << this folder gets blatted

 

Has any kind sir got a script that just does this - or can somebody point me in the right direction .... Pwetty Pwease ?

 

Thanks

  • 1 month later...
Posted

Save this VBScript snippet to Whatever.vbs. Create a text file with the name of each server per line, like:

server1
server2
....

 

Replace "C:\servers.txt" with the name of that text and run the script from a command prompt, like:

 

cscript /nologo Whatever.vbs

 

Here's the code:

 

serverList = "C:\servers.txt"


Set fso = CreateObject("Scripting.FileSystemObject")


servers = Split(fso.OpenTextFile(serverList, 1, False).ReadAll, vbCrLf)


For Each servername In servers
   
   homePath = "\\" & servername & "\home"
   
   WScript.StdOut.WriteLine "Checking '" & homePath & "'..."
   
   If fso.FolderExists(homePath) Then
       
       On Error Resume Next
       For Each userFolder In fso.GetFolder(homePath).SubFolders
           
           Err.Clear
           WScript.StdOut.Write vbTab & "Emptying '" & userFolder & "'..."
           
           fso.DeleteFile userFolder & "\*.*", True
           
           For Each subFolder In fso.GetFolder(userFolder).SubFolders
               fso.DeleteFolder subFolder, True
           Next
           
           If Err.Number = 0 Then
               WScript.StdOut.WriteLine "Success!"
           Else
               WScript.StdOut.WriteLine "Failed."
           End If
           
       Next
       On Error GoTo 0
       
   End If
Next

 

Let me know how it goes.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...