[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

VBS script help

I am enclosing a scipt I have for modifiying the UPN/SAM for an AD account. I am not strong enough to make this do what I want. I need this to "loop" through about 400 accounts so if I could gte some help with that portion I would appreciate it.

What I want to do is just cut and past the "DN"s and the new UPN & SAM for the accounts into the VBS file and have it loop through all  the entries.


thanks in advance.

T


CODE:

'*****************************************************
' This VBScript code sets the UPN and SAM for a user.

' ------ SCRIPT CONFIGURATION ------
strUserDN = "CN=Pants\,Square,OU=CertTest,OU=Test,OU=CPPI test,OU=Groups,OU=World Headquarters,OU=Office Locations,DC=northamerica,DC=cerner,DC=net"

strNewUserUPN = "SB123457@cerner.net"
strNewUserSAM = "SB123457"

' ------ END CONFIGURATION ---------

set objUser = GetObject("LDAP://" & strUserDN)
objUser.Put "userPrincipalName", strNewUserUPN
objUser.Put "sAMAccountName", strNewUserSAM
objUser.SetInfo
Wscript.Echo "UPN/SAM changed for User name: " & objUser.Get("cn")
'*****************************************************


0
tmack
Asked:
tmack
  • 4
  • 3
1 Solution
 
David LeeCommented:
Hi tmack,

Sorry, but I'm not understanding what you want to do.  Are you saying you want to loop through 400 accounts and change the UPN and SAM on each one?  If so, are you planning to enter all 400 new UPNs and SAMs into the script?

Cheers!
0
 
tmackAuthor Commented:
sorry if I was not clear.

I have all the UPNs and SAMs and DNs in a spread sheet. and I would like to loop through them in this script. If you know how to make it so I can just drop those values in and external file and pull them in or just but them in an external batch file and call them from ther in to the script, if any of this makes sence.

Let me know if your understanding this.

T
0
 
David LeeCommented:
Can you export the spreadsheet to a comma delimited file?  If so, what sequence do the fields appear in?
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
tmackAuthor Commented:
i can export it how ever...I would like it to go DN, UPN, SAM....will that work for you?

T
0
 
David LeeCommented:
tmack,

Ok, try this.  I'm not in a position to test it myself so it may need tweaking.  Also, I got to thinking about the DN and realized that it contains a comma, so we can't export to a comma separated values file.  Instead, we need to export to a Tab separated values file.  That's what this script is set to read.  I'd recommend testing the script with a single entry before proceeding on.

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the path and file name as needed
Set objDataFile = objFSO.OpenTextFile("C:\eeTesting\Test.Txt")
While Not objDataFile.AtEndOfStream
    strBuffer = objDataFile.ReadLine
    arrParams = Split(strBuffer, Chr(9))
    strUserDN = arrParams(0) & ",OU=CertTest,OU=Test,OU=CPPI test,OU=Groups,OU=World Headquarters,OU=Office
Locations,DC=northamerica,DC=cerner,DC=net"
    Set objUser = GetObject("LDAP://" & strUserDN)
    objUser.Put "userPrincipalName", arrParams(1)
    objUser.Put "sAMAccountName", arrParams(2)
    objUser.SetInfo
    Wscript.Echo "UPN/SAM changed for User name: " & objUser.Get("cn")
Wend
objDataFile.Close
Set objDataFile = Nothing
Set objFSO = Nothing
0
 
tmackAuthor Commented:
thanks
0
 
David LeeCommented:
No problem.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now