Re: Running a script against an OU
- From: "ComputerTeacher" <computerteacher-nospame@xxxxxxxxxxxx>
- Date: Fri, 13 Oct 2006 03:17:25 GMT
Thanks Richard. Once again you've been very helpful.
Our actual OU path inclues a space character (i.e. "LDAP://OU=Computer
Accounts,OU=lab1,dc=MyDomain,dc=Com")
Do I need to place a forward slash between Computer and Accounts?
Thanks,
Jeremy
"Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:eRMR9Tn7GHA.4996@xxxxxxxxxxxxxxxxxxxxxxx
ComputerTeacher wrote:
In the following script, what do I have to put in place of "atl-ws-01" to
run the script against an OU called lab1? Can I use the distinguished
name? Or would it be easier to run it with a GPO?
strComputer = "atl-ws-01"
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,
user")
objUser.SetPassword "09iuy%4e"
objUser.SetInfo
I assume you want to set the password for the local Administrator account
on all computers in an OU. This can be done using a Startup script in a
GPO, but it would run every time the machines start. There might be other
ways as well, but it can be done in bulk in one script. The trick is that
you must use the WinNT provider to bind to the computer to access local
accounts (the local SAM account database is not LDAP compliant). However,
the WinNT provider is blind to OU's, so you must use the LDAP provider to
bind to the OU. Also, you have to use the NT name of the computer, called
the NetBIOS name, with the WinNT provider. The trick here is to know that
the sAMAccountName attribute of the computer object exposed by the LDAP
provider is the NetBIOS name with "$" appended on the end. I would try
something similar to:
===========
' Bind to the OU with the Distinguished Name.
Set objOU = CreateObject("LDAP://ou=lab1,dc=MyDomain,dc=com")
' Filter on computer objects.
objOU.Filter = Array("computer")
' Enumerate the computer objects.
For Each objComputer In objOU
' Retrieve the NetBIOS name so we can bind with the WinNT provider.
' The NetBIOS name is the sAMAccountName with the trailing "$" removed.
strNTName = objComputer.sAMAccountName
' Remove the trailing "$".
strNTName = Left(strNTName, Len(strNTName) - 1)
' Bind to the local Administrator user on the computer.
Set objAdmin = GetObject("WinNT://" & strNTName &
"/Administrator,user")
' Set the password.
objAdmin.SetPassword "09iuy%4e"
Next
===========
The SetPassword method is immediate, so you should not need to invoke the
SetInfo method.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Follow-Ups:
- Re: Running a script against an OU
- From: Richard Mueller
- Re: Running a script against an OU
- References:
- Running a script against an OU
- From: ComputerTeacher
- Re: Running a script against an OU
- From: Richard Mueller
- Running a script against an OU
- Prev by Date: Re: Running a script against an OU
- Next by Date: logon script for an examination account
- Previous by thread: Re: Running a script against an OU
- Next by thread: Re: Running a script against an OU
- Index(es):
Relevant Pages
|