BiggerDave
Technical User
I need a script to disable users in AD by there sAMAccountName, also I want it to reference a txt file that contains the list of sAMAccountNames.. Please Help
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
' open your text file
Set objFile = objFSO.OpenTextFile("C:\Accounts.txt", ForReading)
' read your file and break into an array
arrTemp = Split(objFile.ReadAll)
objFile.Close
' loop through your array
For i = 0 To UBound(arrTemp)
userName = arrTemp(i)
' if the line is not empty call function
If Not userName = "" Then
' call GetUser function
GetUser userName
End If
Next
Function GetUser(strUserName)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select samAccountName, AdsPath From " & _
"'LDAP://ou=root,dc=allianz-uk,dc=co,dc=uk' " & _
"Where samAccountName = '" & strUserName & "'"
objCommand.Properties("SearchScope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
Wscript.Echo "The samAccount name is not being used."
Else
Wscript.Echo "The samAccount name is being used."
End If
End Function