Mike wrote:
[Quoted Text] > Need a script or command to run on specific OU's in AD and save the > Computer Object names to a text file.
Run any command line utility or script that outputs computer names in the OU at a command prompt and redirect the output to a text file. A VBScript example: ============ Option Explicit Dim objOU, objComputer
' Bind to OU with Distinguished Name. Set objOU = GetObject("LDAP://ou=Sales,dc=MyDomain,dc=com")
' Filter on objects of class computer. objOU.Filter = Array("computer")
' Enumerate computer objects. For Each objComputer In objOU ' Output Distinguished Name of computer. Wscript.Echo objComputer.distinguishedName Next ================ If this program is saved in the file EnumComputers.vbs, run it at a command prompt with the command:
cscript //nologo EnumComputers.vbs > computers.txt
This creates the file computers.txt (in the current directory) with the Distinguished Names of all computers in the specified OU. If instead you want the NetBIOS names, replace "objComputer.distinguishedName" with "objComputer.sAMAccountName". This will be the NetBIOS name with "$" appended on the end.
Alternatively, you can use adfind or dsquery. Again, you would specify the OU as the base of the search, search for objects of class computer, and redirect the output to a text file. The syntax for adfind would be similar to:
adfind -b ou=Sales,dc=MyDomain,dc=com -f "objectCategory=computer" sAMAccountName
You can download adfind.exe from:
http://www.joeware.net/freetools/index.htm
Check this link for info on dsquery:
http://technet2.microsoft.com/windowsserver/en/library/46ba1426-43fd-4985-b429-cd53d3046f011033.mspx#BKMK_1
-- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net --
|