Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

need help modifying script

Can someone help me modify this script?  I need it to run for only the logged in user.
It 'does' - BUT it shows X number of wscript popup windows as it's looping through userlist until it finds the correct user.
I'd like to make the "X" number be 'just' the one where they match please.
It was scary this week with 80 users in that list - I'm worried that when we have 200 users in the list, it will abend the system....

Set WshNetwork = WScript.CreateObject("WScript.Network")
strUser = WshNetwork.UserName

Const ADS_SCOPE_SUBTREE = 2
Const ADS_SECURE_AUTHENTICATION = 1

AdminUser  = "XXXX"
AdminPswd  = "XXXX"
InputFile = "\\Server\share\userlist.txt"
DC1        = "XdomainX"
DC2         = "com"

Set FSO    = CreateObject("Scripting.FilesyStemObject")
Set oFile  = FSO.OpenTextFile(InputFile)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand    = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

Set openDS = GetObject("LDAP:")

Do until oFile.AtEndOfLine
   LineIn = oFile.ReadLine
   strData  = Split(LineIn, ",")
   If Ubound(strData) > 0 Then
      strData(0) = trim(strData(0))   ' current username
      strData(1) = trim(strData(1))   ' new username
      if lcase(strData(0)) = lcase(strUser) then
        objCommand.CommandText = _
          "SELECT distinguishedName FROM 'LDAP://dc=" & DC1 & ",dc=" & DC2 & "' " & "WHERE objectCategory = 'user' " & _
             "AND SAMAccountName = '" & strUser & "'"
            Set objRecordSet = objCommand.Execute
           objRecordSet.MoveFirst
           Do Until objRecordSet.EOF
              DN = objRecordSet.Fields("distinguishedName").Value
              Set usr = openDS.OpenDSObject("LDAP://" & DC1 & "." & DC2 & "/" & DN, AdminUser, AdminPswd, ADS_SECURE_AUTHENTICATION)
              usr.put "samAccountName", strData(1)
              usr.put "userPrincipalName", strData(1) & "@" & DC1 & "." & DC2
              usr.SetInfo
              usr.SetPassword "xxxxxx"
             'fso.GetFolder("F:\Users\" & strData(0)).Name = strData(1)
             'msgbox "About to rename " & strData(0) & " to " & strData(1)
             FSO.GetFolder("\\Server\USERS\" & strData(0)).Name = strData(1)
             FSO.GetFolder("\\Server\HDBackup\" & strData(0)).Name = strData(1)
           objRecordSet.MoveNext
         Loop
      End if
   End If
Loop

oFile.Close
msgbox "Processing completed at " & now()
Set usr = Nothing
Set objCommand.ActiveConnection = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set openDS = Nothing
Set oFile = Nothing
Set FSO = Nothing
wscript.quit
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sirbounty

ASKER

I'm sorry Lynn - I should've seen that.
Sure it was shelling for each account - didn't think to check before running the process - duh... :(
5 hours sleep for the past 48 could be the problem, eh?
Glad I get next weekend off...haha.
Thanx again!
You're welcome...

Yeah, lack of sleep will do that.  It'll make an ol' man outta ya before your time. Just look at me... grey hair, half deaf, can't see, can't remember... and I'm only 57 ;-)

Like I said, I didn't observe the problem you described.  I'm actually surprised the modified script I posted performs detectably different from yours... you already had an "if" statement checking for a match on username before any real work was attempted and mine only differs by being more "modular" and obvious. The only different functionality is to terminate immediately after the user is changed which would only keep it from reading the rest of the input file.

Anyway, I'm glad it worked out for you.  Thanx for the grade/points and get some rest!

-- Lynn
Finally left that horrid place, but I still have to provide remote support.
Just wanted to clarify - the multi-windows I was seeing was from a shell within VB - if I simply ran the VBS, it behaved very nicely.
Thanx again. :)
>> Finally left that horrid place<<

Temporary vacation... or permanent?  

Thanks for the clarification... I thought I might have been overlooking something critical... I must have missed the part about "VB" & "shell".  I'm glad it worked for you.

You're welcome and good luck,
Lynn
Niether - it was a remote office I was working out of.
You know - most of the problems could probably be attributed to a crappy network.
Found out on Monday that their switch ports were all misconfigured and mislabled...can't wait till we get them on our network...
Time for my catch-up nap... :)
I can identify with that.  Back in '91 when I started with my former employer they had a similar situation.  The "network manager" (I'm being VERY loose with that term in this case) had cabled the room with the servers, routers, switches, Northern Telecom  phone switch, and big Xerox laster printers (connected to mainframes in 4 remote cities) all sitting on raised floor.  Some of the tiles of the floor were bulging upwards from the mass of cabling below... step in the wrong place and parts of the network quit working.  The guy that hired me (he eventually became the CTO) spent an entire weekend from 6PM Friday night til 10AM Monday morning pulling out cables, labelling, rerouting and reinstalling them... a significant amount of the cabling wasn't even connected anywhere.  I came aboard just after that so I missed most of that pain.  Unfortunately, the "logical" side of the infrastructure was just about as bad as the "physical"... that's why I was brought in.  

After spending 12+ years getting the business processes and I.T. support organized, developing several new products for our 500+ clients and growing it from 150 employees to around 2000 only to see new excutive management come in for the third time and tell us how bad we were doing was more than I could take... so I quit taking it and here I am!  BTW, the CTO (my longtime friend of 30 years and immediate superior) was replaced with a new CTO, 4 Senior new VP's, 4 new Project Leaders, and a raft of "foreign contractors"... so you can imagine the workload and responsibility we were sharing.

Don't nap too long... life is moving at an ever increasing pace! :-)