Calling on vbscript and powershell experts for help

Ron Shorts
Ron Shorts used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
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?
Lead SaaS Infrastructure Engineer
Commented:
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.

Author

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.

Author

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 Engineer
Commented:
@Ron,

Abo3ut Line 29, yes, you're right, I mistook it for being the statement under the "if null " section.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial