I have a script that deletes computers that works most of the time, but not all of the time:
So I'm trying to trap the errors with the following changes:
My trap doesn't work, because err.number always equals -2147016690 regardless of whether the computer object successfully deleted or not. Shouldn't it be 0 if the DomainObj.Delete is successful?
Code:
'***************************************************
'* Connect to the Domain *
'***************************************************
Set DomainObj = GetObject("WinNT://" & DomainString)
'***************************************************
'* Write Log File entry *
'***************************************************
If CompAge > 360 Then
objFileRpt.writeline "Deleted Computer " & Computer & " that has not been accessed in " & CompAge & " days<br>"
count = count + 1
'***************************************************
'* Delete the Computer *
'***************************************************
DomainObj.Delete "computer", CompString
end if
So I'm trying to trap the errors with the following changes:
Code:
'***************************************************
'* Connect to the Domain *
'***************************************************
Set DomainObj = GetObject("WinNT://" & DomainString)
'***************************************************
'* Delete the Computer *
'***************************************************
If CompAge > 360 Then
DomainObj.Delete "computer", CompString
wscript.echo err.number
'***************************************************
'* Write Log File entry *
'***************************************************
If Err.Number <> 0 Then
objFileRpt.writeline "Could not Delete Computer " & Computer & " Please delete manually<br>"
Else
objFileRpt.writeline "Deleted Computer " & Computer & " that has not been accessed in " & CompAge & " days<br>"
count = count + 1
End If
end if
My trap doesn't work, because err.number always equals -2147016690 regardless of whether the computer object successfully deleted or not. Shouldn't it be 0 if the DomainObj.Delete is successful?