Re: Changing the local admin password base on the computer's OU
- From: "Al Dunbar" <alandrub@xxxxxxxxxxx>
- Date: Wed, 25 Feb 2009 08:25:13 -0500
"Myrddin" <MyrddinMT@xxxxxxxxx> wrote in message
news:de67ce58-eaa2-43ab-a448-f4011c82836e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Feb 25, 11:39 am, "Vasil Bachvarov" <v_bachva...@xxxxxxxxxxx>
wrote:
Hi again,
And maybe a third recommendation:
3. You can put the common code of the two IF-bodies in front of them, so
you
do not have duplicate code. In case you have to change something, you
would
do it only in 1 place, not in 2.
However, you should be careful that the 3 moved lines will be executed
always, regardless of the conditions (which does not seem to be a problem
in
this current case).
Here is your modified code:
=================
Dim WshNetwork, Sh, fso, WSHShell
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Sh = WScript.CreateObject("WScript.Shell")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
ComputerName = WshNetwork.ComputerName
' The following 3 lines are common for both conditions and executed before
them.
Set Shell = Wscript.CreateObject ("Wscript.Shell" )
strComputer = Shell.ExpandEnvironmentStrings ("%COMPUTERNAME%" )
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,
user" )
Set oGroup_TEST1 = GetObject("LDAP://CN=" & ComputerName &
",OU=TEST1,OU=Computers,OU=Modeling,DC=<domain>,DC=xx")
Set oGroup_TEST2 = GetObject("LDAP://CN=" & ComputerName &
",OU=TEST2,OU=Computers,OU=3D,DC=<domain>,DC=xx")
'Change the local admin pwd for OU TEST1
If oGroup_TEST1.IsMember("WinNT://<domain>/" & ComputerName) Then
objUser.SetInfo
objUser.SetPassword "TEST1"
ElseIf oGroup_TEST2.IsMember("WinNT://<domain>/" & ComputerName) Then
'Change the local admin pwd for OU TEST2
objUser.SetPassword "TEST2"
objUser.SetInfo
End If
=======================
"Vasil Bachvarov" <v_bachva...@xxxxxxxxxxx> wrote in message
====> Is the name of your domain actually "<domain>"? If not, then the code
you are showing is not exactly what you are running.
Thanks for the reply.
I modified my code with your help, but I'm still getting the same
problem, no matter which OU the computer is in (test1, test2, xxx or
yyy etc.) it comes out as being in the first OU that the script tests
(test1 in this case, whereas the computer is actually in test2).
This leads me to think either the condition or the GetObject is wrong.
I've tried both of these with the same results :
Set oGroupe_TEST1 = GetObject("LDAP://CN=" & ComputerName &
",OU=TEST1, OU=Computers, OU=modeling,DC=<domain>,DC=xxx")
and
Set oGroupe_TEST1 = GetObject("LDAP://CN=" & ComputerName &
",OU=modeling,OU=Computers,OU=TEST1 ,DC=<domain>,DC=xxx")
My test OU's look like this :
TEST1
Computers
Modeling
3D
TEST2
Computers
Modeling
3D
I'm less and less sure about the if condition " If
oGroup_TEST1.IsMember("WinNT://<domain>/" & ComputerName) Then " but
I've been at this for a quite a while now and can't seem to be
objective anymore.
====> Been there, done that.
The issue here is the same as your original problem: all of your tests give
a true result. This means that they are not testing the condition you think
they are testing.
I am surprised that your code is not throwing an error. These two statements
cannot possibly both return valid computer objects, as the indicated
computer cannot be in two different OU's:
Set oGroup_TEST1 = GetObject("LDAP://CN=" & ComputerName &
",OU=TEST1,OU=Computers,OU=Modeling,DC=<domain>,DC=xx")
Set oGroup_TEST2 = GetObject("LDAP://CN=" & ComputerName &
",OU=TEST2,OU=Computers,OU=3D,DC=<domain>,DC=xx")
Next, I do not know what it means to test for a computers membership in
anything other than a group, so I do not know what it means to test a
computer's membership in a WinNT-based object that appears to represent
itself.
I would suggest you modify the code to verify what the oGroup_test1 and etc
objects actually refer to.
/Al
.
- References:
- Changing the local admin password base on the computer's OU
- From: Myrddin
- Re: Changing the local admin password base on the computer's OU
- From: Vasil Bachvarov
- Re: Changing the local admin password base on the computer's OU
- From: Vasil Bachvarov
- Re: Changing the local admin password base on the computer's OU
- From: Myrddin
- Changing the local admin password base on the computer's OU
- Prev by Date: Re: Changing the local admin password base on the computer's OU
- Next by Date: Highlighting cell based on condition
- Previous by thread: Re: Changing the local admin password base on the computer's OU
- Next by thread: Re: Changing the local admin password base on the computer's OU
- Index(es):
Relevant Pages
|