Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

POWERSHELL ACTIVE DIRECTORY: ADD OR UPDATE PROXYADDRESSES IN USER PROPERTIES ATTRIBUTE EDITOR

June 25, 2017 04:20PM

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

automate Powershell Active Directory User Properties Attribute Editor, ProxyAddresses Add value smtp, sip

Copy below script to ps1 file. Below is the formate of CSV file.

   ----------------------------------------------
   | user      | emailid                        |
   | --------------------------------------------
   | ku0f1999  | kunal@vcloud-lab.com           |
   | md0f2011  | mahesh@vcloud-lab.com          |
   ----------------------------------------------
 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  | kunal@vcloud-lab.com           |
   | md0f2011  | mahesh@vcloud-lab.com          |
   ----------------------------------------------
  .OutPuts  
   username ProxyAddresses
   -------- --------------
   {}       {sip:ku0f1999@vcloud-lab.com, SMTP:ku0e1123@testaccount.com, smtp:Kunal@vcloud-lab.com, }
   {}       {sip:md0f2011@vcloud-lab.com, SMTP:md0f2011@testaccount.com, smtp:mahesh@vcloud-lab.com}
   
  .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 = "{0}:{1}" -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.

Powershell Active Directory Module Add user proxyaddresses value, automation, view advanced feature

Go Back

Nice one. As always, thanks for sharing!



Comment