This was second script I wrote for user migrating from domain change (exchange to office 365). (Although I have basic knowledge of Exchange server, but I was involved due to my PowerShell scripting knowledge), Requirement was adding new email address to ProxyAddresses under Attribute Editor (AD Users Properties - View advanced features) retaining existing values.
Check out my earlier script on using Active directory Powershell.
POWERSHELL ACTIVE DIRECTORY: ADD OR UPDATE (CHANGE) MANAGER NAME IN ORGANIZATION TAB OF USER
Add multiple proxy addresses with Microsoft PowerShell in Active Directory Groups
Copy below script to ps1 file. Below is the formate of CSV file.
---------------------------------------------- | user | emailid | | -------------------------------------------- | ku0f1999 | [email protected] | | md0f2011 | [email protected] | ----------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<# .Synopsis Add smtp id to existing active directory user proxyaddress. .Description Run this script on domain controller. It will add addition record to proxy addresses in user properties, and keep the existing as it is. .Example Add-UserProxyAddress -CSVFile c:\tenp\users.csv It takes input from CSV file and add the smtp records in respective user proxy address attributes. .Example CSV file data format and example ---------------------------------------------- | user | emailid | | -------------------------------------------- | ku0f1999 | [email protected] | | md0f2011 | [email protected] | ---------------------------------------------- .OutPuts username ProxyAddresses -------- -------------- {} {sip:[email protected], SMTP:[email protected], smtp:[email protected], } {} {sip:[email protected], SMTP:[email protected], smtp:[email protected]} .Notes NAME: Add-UserProxyAddress AUTHOR: Kunal Udapi CREATIONDATE: 01 DECEMBER 2016 LASTEDIT: 3 February 2017 KEYWORDS: Add or update proxyaddress smtp on active directory user account .Link #Check Online version: http://kunaludapi.blogspot.com #Check Online version: http://vcloud-lab.com #Requires -Version 3.0 #> #requires -Version 3 [CmdletBinding()] param( [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)] [alias('FilePath','File','CSV','CSVPath')] [String]$Path, [String]$Protocol='SMTP') #param Begin { Import-Module ActiveDirectory } #Begin Process { $users = Import-Csv -Path $Path #$users = Get-ADUser -Filter * -SearchBase "OU=TestOu,DC=Rageframeworks,DC=com" -Properties ProxyAddresses $temp = [System.IO.Path]::GetTempFileName() Foreach ($u in $users) { #$smtpid = "smtp: {0}.{1}@kumarthegreat.com" -f $u.givenName, $u.Surname Try { $user = Get-ADUser -Identity $u.user -ErrorAction Stop Write-Host "$($user.SamAccountName) exists, Processing it..." -BackgroundColor DarkGray -NoNewline $emailid = "{1}:{0}" -f $u.emailid, $Protocol Set-ADUser -Identity $u.user -Add @{Proxyaddresses=$emailid} Write-Host "...ProxyAddress added" -BackgroundColor DarkGreen } #Try catch { Write-Host "$($user.SamAccountName) does not exists" -BackgroundColor DarkRed } } #Get-ADUser -Filter * -SearchBase "OU=TestOu,DC=Rageframeworks,DC=com" -Properties ProxyAddresses | select username, ProxyAddresses $users | foreach { $user = $_.user Try { Get-ADUser -Identity $_.user -Properties ProxyAddresses -ErrorAction Stop | select SamAccountName, Name, ProxyAddresses } #try catch { Write-Host "$user does not exists" -BackgroundColor DarkRed } } | Out-File $temp } #Process end { Notepad $temp } |
Once script is executed, it shows the user name successful message, also notepad is opened with result. I have written another script for adding information to Group ProxyAddresses as well. Same can be found on https://github.com/kunaludapi/Powershell-AD-Add-user-proxyaddresses.
Useful articles
POWERSHELL: INSTALLING AND CONFIGURING ACTIVE DIRECTORY
POWERSHELL ACTIVE DIRECTORY: ADD OR UPDATE (CHANGE) MANAGER NAME IN ORGANIZATION TAB OF USER
POWERSHELL ACTIVE DIRECTORY: ADD OR UPDATE PROXYADDRESSES IN USER PROPERTIES ATTRIBUTE EDITOR
Powershell one liner: Create multiple user accounts
Active Directory Powershell: Create bulk users from CSV file