Calling on vbscript and powershell experts for help

Need some help with deciphering this vbscript... this script first runs a dsquery to grab all users and DN's into a file.

Basically line 12, I'm looking to grab the DN where it builds a strNullset variable to determine if @Domain or @Domain2.org - is there a way to do this in powershell without dumping out all of the users in a file, then append later in the script?

Also looking for what line 24 actually does with the "2", and also what line 29 does... ?




Set objArgs = WScript.Arguments

If objArgs.Count < 1 Then
	Wscript.Quit -1
End If
Const ADS_PROPERTY_APPEND = 3
strUserDN = objArgs(0)

Set objUser = GetObject("LDAP://" & strUserDN)
If UCase(objUser.AccountDisabled) = "FALSE" Then 
	strNullSet = objUser.sAMAccountName & "@Domain.org" 
	If InStr(UCase(strUserDN),"Domain2") Then   
		strNullSet = objUser.sAMAccountName & "@Domain2.org"
		End If
	If objUser.mail = "" Then                             
		If objUser.userPrincipalName = strNullSet Then 
		Else
			objUser.put "userPrincipalName", strNullSet    
			WScript.Echo objUser.sAMAccountName & "," & strNullSet & "," & objUser.userPrincipalName & "," & "Null"
		End If
	Else
		If objUser.userPrincipalName = objUser.mail Then  
			strO365Alias = "smtp:" & objUser.sAMAccountName & "@cchs.mail.onmicrosoft.com"
			If objUser.mailNickname = objUser.sAMAccountName & "2" Then
				strO365Alias = "smtp:" & objUser.sAMAccountName & "2@mail"
			End If
			objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", Array(strO365Alias)
		Else
			objUser.put "userPrincipalName", objUser.mail
		End If
	End If
	If objUser.customeAttribute1 = strNullSet Then
	Else
		objUser.put "customAttribute1", strNullSet
	End If
	objUser.SetInfo
End If

Open in new window


Thanks experts!
Ron ShortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPRetiredCommented:
It would be easier if you stated what you have i.e. what are the arguments and what you want.

"smtp:" & objUser.sAMAccountName & "2@mail" ???

It looks like you want to change domain1.org to domain2.org?
Ben Personick (Previously QCubed)Lead SaaS Infrastructure EngineerCommented:
Line 24 checks if the user's Nickname is the SamAccountName followed by 2.

If this is true, it sets the " o365Alias "address to that value "(SamAccountName&2)@mail"

Why isn't it supposed to be "(SamAccountName&2)@cchs.mail.onmicrosoft.com"

Line 29 creates a user principle name for the object because none existed.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ron ShortsAuthor Commented:
David - this adds the samaccountname of each and appends @domain.org unless the distinguishedname flags the other OU it's it (Domain2 for example) where I have another suffix; another OU,  @domain2.org it appends to if Domain2 is in the path in the DN.
Ron ShortsAuthor Commented:
Ben - perhaps the "2" is if there is already an entry for the samaccountname, and the 2 is in case this is added twice?

I think line 29 replaces the userprincipalname with what's in the mail attribute, does that make sense?
Ben Personick (Previously QCubed)Lead SaaS Infrastructure EngineerCommented:
@Ron,

Abo3ut Line 29, yes, you're right, I mistook it for being the statement under the "if null " section.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.