Archive

Archive for the ‘Exchange 2007’ Category

Change primary proxyAddresses

November 12th, 2008 2 comments

This script creates and sets a new Primary E-mail Address based on:

  • Organizational Unit;
  • UPN Suffix.

The way the new  Primary E-mail Address is build depends on the way your sAMAccountName is build. This is something you can adjust the way you like. In the script below it is set to:

“1st letter givenName.something in between.sn@email domain”

For example:

m.vander.plas@martius.nl

Variables you can adjust are:

  • LDAP Connection;
  • EmailDomain;
  • UPNSuffix;
  • PriEmailAddress (the way it is set-up).

And then now the script you came for!

On Error Resume Next

Dim objRecip

Const ADS_PROPERTY_UPDATE = 2

‘ LDAP connection to specific OU
Set CNUsers = GetObject (“
LDAP://OU=Personel,OU=Accounts,DC=testdomain,DC=local“)
CNUsers.Filter = Array(“user”)
For Each User in CNUsers

‘ #### Edit below here ####
EmailDomain = “domain.com”  ’ Put your mail domain here
UPNSuffix = “testdomain.local”  ’ Put the UNP suffix to which this script applies to here
PriEmailAddress = LCase(LEFT(givenName,1)) &LCase(RIGHT(User.sAMAccountName, Len(User.sAMAccountName) – InStr(User.sAMAccountName, “.”)+1)) &”@” &EmailDomain
‘ #### No editing below here ####
givenName = User.givenName
sn = User.sn
sAMAccountName = User.sAMAccountName
userPrincipalName = User.userPrincipalName
SamUPN = User.sAMAccountName &”@” &UPNSuffix
sAddress = “SMTP:”&PriEmailAddress
Set objRecip = User

‘ ********************************
‘  For test purposes only
‘ MsgBox (“PriEmailAddress = “&PriEmailAddress)
‘ ********************************

If Not userPrincipalName = SamUPN Then

‘ Do Nothing

Else

‘ Disable”Automatically update e-mail addresses based on recipient policy”
User.PutEx ADS_PROPERTY_UPDATE, “msExchPoliciesExcluded”, Array(“{26491CFC-9E50-4857-861B-0CB8DF22B5D7}”)
User.SetInfo

‘ Remove already present email address which is the same that is created later on. This is a dirty check, but it works :-)
User.PutEx 4, “ProxyAddresses”, Array(“smtp:”&PriEmailAddress)
User.SetInfo

‘ ##### Begin creation new primary E-mail Address #####
bIsFound = False

vProxyAddresses = objRecip.ProxyAddresses
nProxyAddresses = UBound(vProxyAddresses)

i = 0

Do While i <= nProxyAddresses
email = vProxyAddresses(i)
If Left (email,5) = “SMTP:” Then
vProxyAddresses (i) = “smtp:” & Mid (email,6)
End If

If vProxyAddresses(i) = sAddress  Then
IsFound = True
Exit Do
End If

i = i + 1

Loop

If Not bIsFound Then
ReDim Preserve vProxyAddresses(nProxyAddresses + 1)
vProxyAddresses(nProxyAddresses + 1) = sAddress
objRecip.ProxyAddresses = vProxyAddresses
User.SetInfo
End If
‘ ##### Endcreation new primary E-mail Address #####

‘ Adjusting E-mail description field to new primary e-mail address
User.Put “mail”, PriEmailAddress
User.SetInfo

End If

Next

‘ ********************************
‘  For test purposes only
‘ MsgBox (“Einde Script :-) ”)
‘ ********************************

Easy exch2k7 csv bulk user import with new-mailbox script

July 25th, 2008 No comments

Even om aan te geven dat deze blog echt van een nerdo is hieronder een script waarmee je eenvoudig een x aantal gebruikers kan importeren uit een csv bestand in een omgeving van Windows Server 2008 en Exchange 2007. Het is een PowerShell script overigens.

De eerste regel van het csv bestand ziet er als volgt uit:

FirstName,LastName,Name,Alias,UserPrincipalName,SamAccountName,Title,Password,Database,

OrganizationalUnit

Een nieuwe variable toevoegen kan door deze achteraan bij te voegen en in onderstaand script het op te nemen met <variabele naam> $_.<variabele naam>. Deze variabele naam is dus de toevoeging aan het cvs bestand. In onderstaand voorbeeld is namelijk 1( Title) van de vele variabelen uit Set-User meegenomen.

Function secureit( $string )
{
$ss = New-object System.Security.SecureString
$string.GetEnumerator() | foreach-object { $ss.AppendChar( $_ ) }
$ss
}

import-csv c:\New-MailboxUser.csv | foreach-object {New-Mailbox -Name $_.Name -Alias $_.Alias -OrganizationalUnit $_.OrganizationalUnit -UserPrincipalName $_.UserPrincipalName -SamAccountName $_.SamAccountName -FirstName $_.FirstName -LastName $_.LastName -Password (secureit $_.Password) -ResetPasswordOnNextLogon $true -Database $_.Database}

import-csv c:\New-MailboxUser.csv | foreach-object {set-user -identity $_.UserPrincipalName -Title $_.Title}

Opslaan als .ps1 bestand en plaatsen in de script directory van Exchange 2007. CSV bestand plaatsen in het opgegeven pad, hier is dat C:\.

Mocht je het csv bestand aanmaken in Excel zorg en dan voor dat jet het bestand na bewerkt door alle ; te vervangen door een ,(komma). Daarbij is bovenstaand script eenvoudig uit te breiden met meerdere regels die importeren uit hetzelfde csv bestand. Het toevoegen aan groepen zou bijv. ook tot de mogelijkheden kunnen behoren.

Op deze manier zijn er geen extra tools nodig van bijv. Quest.