Link to home
Start Free TrialLog in
Avatar of Ron Shorts
Ron ShortsFlag for United States of America

asked on

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!
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

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?
ASKER CERTIFIED SOLUTION
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
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 Ron Shorts

ASKER

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.
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?
SOLUTION
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