Thursday, July 27, 2006

Correcting SIP Addresses

If a user changes his email address then he may well not be able to log into LCS anymore due to that not matching his logon.

This script cycles AD and checks for mismatches. If you specify /commit it will write the changes back to AD.

'==========================================================================
'
'
'
' NAME: SIPFix.vbs
'
' AUTHOR: Stuart Bennett
' DATE : 26-05-2006
'
' Usage: sipfix.vbs
' e.g. sipfix.vbs out.csv /write
'
' COMMENT: Update all those pesky sip addresses to primary SMTP.
'
'==========================================================================


On Error Resume Next
' Change the xx throughout to your domain name..
OUMasterPath = "LDAP://OU=User,OU=Accounts,DC=emea,DC=xx,DC=com
Dim filename : filename = LCase(Trim(WScript.Arguments(0)))
Dim commit : commit = LCase(Trim(WScript.Arguments(1)))
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim fout : set fout = oFS.OpenTextFile(filename, 2, True, -2)
On Error GoTo 0

Set objTOPOU = GetObject(OUMasterPath)
For Each objOU In objTOPOU
wscript.echo("Processing Site : " & objOU.name)
Call SubOU(objOU.Name)
Next
fout.Close


Sub SubOU(theOU)
strOUPath = "LDAP://" & theOU & ",OU=User,OU=Accounts,DC=emea,DC=xx,DC=com"
Set objTestOU = GetObject(strOUPath)
For Each objUser in objTestOU
GetSIPContact fout, objUser
Next
End Sub

Sub GetSIPContact(fout, objUser)
On Error Resume Next
objUser.Get("msRTCSIP-PrimaryUserAddress")
if (Err.Number = 0) Then
SIPName=LCase(objUser.Get("msRTCSIP-PrimaryUserAddress"))
PrEmail=lcase(objuser.mail)
SIPName=Replace(sipname,"sip:","")
If trim(SIPNAME) <> trim(PrEmail) Then
wscript.echo(objUser.DisplayName & ";" & SIPName & ";" & prEmail)
fout.WriteLine(objUser.DisplayName & ";" & SIPName & ";" & prEmail)
If lcase(commit)="/write" Then
realSIP="sip:" & prEmail
wscript.echo ("Changing " & objuser.name)
objuser.PUT "msRTCSIP-PrimaryUserAddress",realSIP
objuser.setinfo
End If
End If
Else
Err.Clear
End If
On Error Goto 0
end Sub