LBMCreation
Technical User
Hi, I have a script which clears all users from groups located in a excel file.
The problem is that i have getting random errors stating:
Line 51
Char 2
Name translation; Could not find the name or insufficent right to see name
code: 80072116
SOurce: (null)
Sometimes it works and sometimes i get the above error.
any ideas why this is happening?
Here is my script
OPTION EXPLICIT
dim strFilter, strRoot, strScope, strGroupName, TimeNow, objWS
dim strNETBIOSDomain, strGroupDN, objSpread, DateNow, strFilePath, objFiletxt, objFSO
dim cmd, rs,cn, objGroup, strSheet, objExcel, intRow, wshShell, strTemp, objTempMessage, strWindowTitle, strTempVBS, objProgressMsg
Const ForReading = 1
Const OpenAsASCII = 0
Const ADS_PROPERTY_CLEAR = 1
strWindowTitle = "Running LMS Delete Script"
ProgressMsg "Deleting Users From Groups, Please wait.", strWindowTitle
strSheet = "C:\EXCELSCRIPT\EXCELFILE.xlsm"
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
Wscript.Sleep 3000
Set objWS = objExcel.ActiveWorkBook.WorkSheets("Delete")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
strGroupName = Trim(objExcel.Cells(intRow, 1).Value)
intRow = intRow + 1
strNETBIOSDomain = "REALDOMAINHIDDEN"
strGroupDN = GetDN(strNETBIOSDomain,strGroupName)
set objGroup = getobject("LDAP://" & strGroupDN)
objGroup.PutEx ADS_PROPERTY_CLEAR, "member", 0
objGroup.SetInfo
Wscript.Sleep 1000
Loop
ProgressMsg "", strWindowTitle
strWindowTitle = ""
ObjExcel.Quit
Wscript.Sleep 10000
run "LMS_AddToGroups.vbs"
Function GetDN(byval strDomain,strObject)
DIM objTrans
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 1, strDomain
objTrans.Set 3, strDomain & "\" & strObject
GetDN = objTrans.Get(1)
end function
' Progress MSG
Function ProgressMsg( strMessage, strWindowTitle )
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
If strMessage = "" Then
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Exit Function
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempVBS = strTEMP + "\" & "Message.vbs"
Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
objTempMessage.Close
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )
Set wshShell = Nothing
Set objFSO = Nothing
End Function
Sub Run(ByVal sFile)
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub
EXCEL FILE:
COL A
Header
Group1
Group2
Group3
Group4
Group5
The problem is that i have getting random errors stating:
Line 51
Char 2
Name translation; Could not find the name or insufficent right to see name
code: 80072116
SOurce: (null)
Sometimes it works and sometimes i get the above error.
any ideas why this is happening?
Here is my script
OPTION EXPLICIT
dim strFilter, strRoot, strScope, strGroupName, TimeNow, objWS
dim strNETBIOSDomain, strGroupDN, objSpread, DateNow, strFilePath, objFiletxt, objFSO
dim cmd, rs,cn, objGroup, strSheet, objExcel, intRow, wshShell, strTemp, objTempMessage, strWindowTitle, strTempVBS, objProgressMsg
Const ForReading = 1
Const OpenAsASCII = 0
Const ADS_PROPERTY_CLEAR = 1
strWindowTitle = "Running LMS Delete Script"
ProgressMsg "Deleting Users From Groups, Please wait.", strWindowTitle
strSheet = "C:\EXCELSCRIPT\EXCELFILE.xlsm"
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
Wscript.Sleep 3000
Set objWS = objExcel.ActiveWorkBook.WorkSheets("Delete")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
strGroupName = Trim(objExcel.Cells(intRow, 1).Value)
intRow = intRow + 1
strNETBIOSDomain = "REALDOMAINHIDDEN"
strGroupDN = GetDN(strNETBIOSDomain,strGroupName)
set objGroup = getobject("LDAP://" & strGroupDN)
objGroup.PutEx ADS_PROPERTY_CLEAR, "member", 0
objGroup.SetInfo
Wscript.Sleep 1000
Loop
ProgressMsg "", strWindowTitle
strWindowTitle = ""
ObjExcel.Quit
Wscript.Sleep 10000
run "LMS_AddToGroups.vbs"
Function GetDN(byval strDomain,strObject)
DIM objTrans
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 1, strDomain
objTrans.Set 3, strDomain & "\" & strObject
GetDN = objTrans.Get(1)
end function
' Progress MSG
Function ProgressMsg( strMessage, strWindowTitle )
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
If strMessage = "" Then
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Exit Function
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempVBS = strTEMP + "\" & "Message.vbs"
Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
objTempMessage.Close
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )
Set wshShell = Nothing
Set objFSO = Nothing
End Function
Sub Run(ByVal sFile)
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub
EXCEL FILE:
COL A
Header
Group1
Group2
Group3
Group4
Group5