Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script to change computer description in Active Directory

$
0
0

I have the following script that allows me to disable 500+ computer accounts at once. It works just fine but I am wanting to also have it add a reason why in the Description field. I've looked online and can't seem to find anything.

Can someone add to this code so it will also add what I want to the description field?

Option Explicit

Dim strFile, objFSO, objFile
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
Dim strComputer, strComputerDN, objComputer

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify text file of computer NetBIOS names.
strFile = "C:\Disable.XP\Computers.rAM.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)

' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Read lines from the file.
Do Until objFile.AtEndOfStream
    strComputer = Trim(objFile.ReadLine)
    If (strComputer <> "") Then
        ' Convert NetBIOS name to DN.
        ' NetBIOS name must have "$" appended to end.
        ' Trap error if computer not found.
        On Error Resume Next
        objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strComputer & "$"
        If (Err.Number <> 0) Then
            On Error GoTo 0
            Wscript.Echo "Computer not found: " & strComputer
        Else
            On Error GoTo 0
            strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
            ' Bind to the computer object.
            Set objComputer = GetObject("LDAP://" & strComputerDN)
            ' Disable the computer.
            objComputer.AccountDisabled = True
	    objComputer.SetInfo
        End If
    End If
Loop

msgBox "Computers have been disabled"


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>