#
# NAME: addproxy.ps1
#
# AUTHOR: Erik Enger , PointBridge
# DATE : 3/08/2009
#
# COMMENT: Used to add proxyAddresses read in from a CSV file.
#
# Note: This script requires the Exchange Management Shell Snapin to function. Add this snapin to the Windows PowerShell default profile first.
#
# The c:windowssystem32windowspowershellv1.0profile.ps1 file should contain this line:
#
# add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
#
# ======================================================================
Write-Host `n
## Start a Transcript
$file="C:migrationScriptLogs"
$file+= $_.DisplayName +"-addproxy.log"
Start-Transcript $file -append# Read in TargetAlias field from import file
$newproxy=$_.TargetAlias.Split(‘%’)# Connect to Exchange mailbox
$user=Get-Mailbox -Identity $_.Alias -DomainController dc1.contoso.com
Write-Host "Processing user " $user.Name -foregroundcolor yellow -BackgroundColor darkmagenta# List existing proxyAddresses
Write-Host "Existing proxyAddresses:" $user.EmailAddresses
Write-Host `n# Begin looping through import file and adding any proxyAddresses that are missing
for($i=0;$i -le $newproxy.Count-1;$i++)
{
$newaddr=$newproxy[$i]
if ($user.EmailAddresses -notcontains $newaddr)
{
Write-Host "Adding new proxyAddress: " $newaddr
$user.EmailAddresses.Add("smtp:"+$newaddr)}
else
{Write-Host "Duplicate SMTP address found (" $newaddr ") Skipping addition…"}
}Set-Mailbox -Instance $user -DomainController dc1.contoso.com
$newaddr=""
Write-Host `n
### Stop the log for the current object
Date
Stop-Transcript
}
Write-Host "ProxyAddress additions complete." -foregroundcolor red -BackgroundColor darkmagenta
Write-Host `n`n`n
‘
‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 4.0
‘
‘ NAME: Add proxy address(es) to existing mailbox enable objects
‘
‘ AUTHOR: Erik Enger, PointBridge, LLC
‘ DATE : 9/2/2005
‘
‘ COMMENT: This script is designed to add proxy addresses from a spreasdsheet
‘ to an existing mailbox enabled object
‘
‘==========================================================================
Dim objUser, objContainer
Dim objExcel, objSheet, objRootLDAP
Dim strOUContainer, strDN, strObjectClass
Dim strPathExcel, strPath, strObjCN
Dim strDomain, strOU, strProxy, strMailbox, strNick
Dim arrProxyAddresses
Dim intNumusers, intRunError, intRow, intCol
strPathExcel = "d:migrationscriptsupdate-metadir.xls"
Set objExcel = CreateObject("Excel.Application")
On Error Resume Next
Err.Clear
objExcel.Workbooks.Open strPathExcel
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
WScript.Echo "Edit the path to YOUR spreadsheet " & strPathExcel
Wscript.Quit
End If
On Error GoTo 0
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
‘ Check intRow offset numbers
intRow = 2
‘ For each row, create user and set attribute values.
‘ Loop until Empty cell
strDN = Trim(objSheet.Cells(intRow, 1).Value)
strProxy = Trim(objSheet.Cells(intRow, 7).Value)
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU _
& objRootLDAP.Get("DefaultNamingContext"))
Set objUser = GetObject("LDAP://"& strDN & ",ou=migrated users,dc=contoso,dc=com")
arrProxyAddresses = objUser.proxyAddresses
WScript.Echo "Adding Uniform proxy address: " & strProxy & " to: " & strDN
WScript.Echo
ReDim Preserve arrProxyAddresses(UBound(arrProxyAddresses) + 1)
arrProxyAddresses(UBound(arrProxyAddresses)) = "smtp:" & strProxy
objUser.Put "proxyAddresses", ""
objUser.Put "proxyAddresses", arrProxyAddresses
objUser.SetInfo
intRow = intRow + 1
intNumusers = intNumusers + 1
WScript.Echo intNumusers & " proxy addresses added."
objExcel.Application.Quit
Set objUser = Nothing
Set objContainer = Nothing
Set objSheet = Nothing
Set objExcel = Nothing
Set objRootLDAP = Nothing