Hi, im having an issue with the below. It runs ok however, what I would like it to do is if an error is found with connecting to a computer from the list specified, output the error but continue onto the next machine in the list. What is happening is it comes across a machine, reports the error, but then also reports the files not present from the previous remembered machine. The error from this machine will also create an error onto the next machine in the list when this one connects ok (Hope this makes Sense?)
On Error Resume Next
Set objfso = CreateObject ("Scripting.FileSystemObject")
Set computerList = objfspenTextFile ("C:\Scripts\computerList.txt", 1)
Set outputList = objfspenTextFile ("C:\Scripts\outputList.txt", 8, True)
strFolder = "\AppData\Local\FolderName"
Do While Not computerList.AtEndOfStream
strComputer = computerList.ReadLine
set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "")
if Err.Number <> 0 then
outputList.WriteLine (Now) & vbTab & strComputer & vbTab & "Error connecting to specified computer: " & err.description
Err.Clear
End If
For Each objFolder In objFSO.GetFolder("\\" & strComputer & "\C$\Users\").SubFolders
strUsername = objfolder.Name
If objFSO.FolderExists("\\" & strComputer & "\C$\Users\" & strUsername & strFolder) Then
Set strFolderPath = objFSO.GetFolder("\\" & strComputer & "\C$\Users\" & strUsername & strFolder)
objFSO.DeleteFolder(strFolderPath)
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files deleted"
Else
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files not Present"
End If
Next
Loop
The Computerlist file contains machines names
The output of the log file is below, machine1 and machine3 are online, machine2 is offline:-
29/01/2016 12:21:33 machine1:user1 files not Present
29/01/2016 12:21:33 machine1:user2 files not Present
29/01/2016 12:21:33 machine1:user3 files not Present
29/01/2016 12:21:33 machine1:user4 files not Present
29/01/2016 12:21:33 machine1:user5 files not Present
29/01/2016 12:21:33 machine1:user6 files not Present
29/01/2016 12:21:33 machine1:user7 files not Present
29/01/2016 12:21:33 machine1:user8 files not Present
29/01/2016 12:21:33 machine1:user9 files not Present
29/01/2016 12:21:34 machine1:user10 files not Present
29/01/2016 12:21:34 machine1:user11 files not Present
29/01/2016 12:21:34 machine1:user12 files not Present
29/01/2016 12:21:34 machine1:user13 files not Present
29/01/2016 12:21:55 machine2 Error connecting to specified computer: The remote server machine does not exist or is unavailable
29/01/2016 12:22:38 machine2:user13 files not Present
29/01/2016 12:22:38 machine3 Error connecting to specified computer: Object not a collection
29/01/2016 12:22:38 machine3:user1 files not Present
29/01/2016 12:22:38 machine3:user2 files not Present
29/01/2016 12:22:38 machine3:user3 files not Present
29/01/2016 12:22:38 machine1:user4 files not Present
29/01/2016 12:22:38 machine3:user5 files not Present
29/01/2016 12:22:38 machine3:user6 files not Present
29/01/2016 12:22:38 machine3:user7 files not Present
29/01/2016 12:22:38 machine3:user8 files not Present
29/01/2016 12:22:38 machine3:user9 files not Present
Thanks
On Error Resume Next
Set objfso = CreateObject ("Scripting.FileSystemObject")
Set computerList = objfspenTextFile ("C:\Scripts\computerList.txt", 1)
Set outputList = objfspenTextFile ("C:\Scripts\outputList.txt", 8, True)
strFolder = "\AppData\Local\FolderName"
Do While Not computerList.AtEndOfStream
strComputer = computerList.ReadLine
set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "")
if Err.Number <> 0 then
outputList.WriteLine (Now) & vbTab & strComputer & vbTab & "Error connecting to specified computer: " & err.description
Err.Clear
End If
For Each objFolder In objFSO.GetFolder("\\" & strComputer & "\C$\Users\").SubFolders
strUsername = objfolder.Name
If objFSO.FolderExists("\\" & strComputer & "\C$\Users\" & strUsername & strFolder) Then
Set strFolderPath = objFSO.GetFolder("\\" & strComputer & "\C$\Users\" & strUsername & strFolder)
objFSO.DeleteFolder(strFolderPath)
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files deleted"
Else
outputList.WriteLine (Now) & vbTab & strComputer & ":" & strUsername & vbTab & "files not Present"
End If
Next
Loop
The Computerlist file contains machines names
The output of the log file is below, machine1 and machine3 are online, machine2 is offline:-
29/01/2016 12:21:33 machine1:user1 files not Present
29/01/2016 12:21:33 machine1:user2 files not Present
29/01/2016 12:21:33 machine1:user3 files not Present
29/01/2016 12:21:33 machine1:user4 files not Present
29/01/2016 12:21:33 machine1:user5 files not Present
29/01/2016 12:21:33 machine1:user6 files not Present
29/01/2016 12:21:33 machine1:user7 files not Present
29/01/2016 12:21:33 machine1:user8 files not Present
29/01/2016 12:21:33 machine1:user9 files not Present
29/01/2016 12:21:34 machine1:user10 files not Present
29/01/2016 12:21:34 machine1:user11 files not Present
29/01/2016 12:21:34 machine1:user12 files not Present
29/01/2016 12:21:34 machine1:user13 files not Present
29/01/2016 12:21:55 machine2 Error connecting to specified computer: The remote server machine does not exist or is unavailable
29/01/2016 12:22:38 machine2:user13 files not Present
29/01/2016 12:22:38 machine3 Error connecting to specified computer: Object not a collection
29/01/2016 12:22:38 machine3:user1 files not Present
29/01/2016 12:22:38 machine3:user2 files not Present
29/01/2016 12:22:38 machine3:user3 files not Present
29/01/2016 12:22:38 machine1:user4 files not Present
29/01/2016 12:22:38 machine3:user5 files not Present
29/01/2016 12:22:38 machine3:user6 files not Present
29/01/2016 12:22:38 machine3:user7 files not Present
29/01/2016 12:22:38 machine3:user8 files not Present
29/01/2016 12:22:38 machine3:user9 files not Present
Thanks