Menu

Virtual Geek

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

Add multiple proxy addresses with Microsoft PowerShell in Active Directory Groups

October 26, 2017 03:45PM

This article is second part of POWERSHELL ACTIVE DIRECTORY: ADD OR UPDATE PROXYADDRESSES IN USER PROPERTIES ATTRIBUTE EDITOR, In this part, I will be changing proxy addresses on active directory groups using PowerShell script. This is helpful while migration of bulk users and groups to Microsoft Office 365.Active Directory domain controller Powershell, get-Adgroup, proxyaddress, get-aduser, set-adgroup, set-aduser email, mail, groupcatogary change information

To use it copy below script in Add-ADGroupProxyAddress.ps1 file and the group information in Groups.txt, it is actually a csv file and can be opened with excel file and the sample tables contents in the files are as below. 
   -----------------------------------------------------------
   | Group      | emailid                                      |
   | ----------------------------------------------------------|
   | Group1    | Group1@vcloud-lab.com       |    
   | Group2    | Group2@vcloud-lab.com       |
   -----------------------------------------------------------

Headers of the table should be Group and emailid, Varify it with Import-Csv cmdlet. run command .\Add-AddGroupProxyAddress.ps1 -Path C:\temp\Groups.csv. Once information is set correctly it shows info of Group on console.

This code is available on Github.

 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
77
78
<#  
  .Synopsis  
   Add smtp id to existing active directory Group proxyaddress.
  .Description  
   Run this script on domain controller. It will add addition record to proxy addresses in Group properties, and keep the existing as it is.
  .Example  
   Add-ADGroupProxyAddress -CSVFile c:\tenp\Group.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
   ----------------------------------------------
   | Group      | emailid                        |
   | --------------------------------------------
   | Group1    | Group1@vcloud-lab.com           |
   | Group2    | Group2@vcloud-lab.com           |
   ----------------------------------------------
  .OutPuts  
   GroupName ProxyAddresses
   -------- --------------
   Group1   {sip:Group1@testaccount.com, smtp:Group1@vcloud-lab.com}
   Group2   {sip:Group2@testaccount.com, smtp:Group2@vcloud-lab.com}
   
  .Notes  
   NAME: Add-ADGroupProxyAddress
   AUTHOR: Kunal Udapi
   CREATIONDATE: 01 DECEMBER 2016
   LASTEDIT: 3 February 2017  
   KEYWORDS: Add or update proxyaddress smtp on active directory Group 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) #param
Begin {  
    Import-Module ActiveDirectory
} #Begin

Process {
    $Groups = Import-Csv -Path $Path
    #$Groups = Get-ADGroup -Filter * -SearchBase "OU=TestOu,DC=Rageframeworks,DC=com" -Properties ProxyAddresses

    Foreach ($u in $Groups) {
        #$smtpid = "smtp: {0}.{1}@kumarthegreat.com" -f $u.givenName, $u.Surname
        Try {
            $Group = Get-ADGroup -Identity $u.Group -ErrorAction Stop
            Write-Host "$($Group.SamAccountName) exists, Processing it..." -BackgroundColor DarkGray -NoNewline 
            $emailid = "SMTP:{0}" -f $u.emailid
            Set-ADGroup -Identity $u.Group -Add @{Proxyaddresses=$emailid} 
            #$cpemailid = "smtp:{0}" -f $u.cpemailid
            #Set-ADGroup -Identity $u.Group -Add @{Proxyaddresses=$cpemailid} 
            Write-Host "...ProxyAddress added" -BackgroundColor DarkGreen
        } #Try
        catch {
            Write-Host "$($Group.SamAccountName) does not exists" -BackgroundColor DarkRed
        } #catch
    } #foreach ($u in $Groups) 
    #Get-ADUser -Filter * -SearchBase "OU=TestOu,DC=Rageframeworks,DC=com" -Properties ProxyAddresses | select username, ProxyAddresses
    $TempFile = [System.IO.Path]::GetTempFileName()
    $Groups | foreach {
        $Group = $_.Group
        Try {
            Get-ADGroup -filter {Name -eq $Group} -Properties mail, proxyAddresses -ErrorAction Stop | select Name, Mail, GroupCategory, @{N='ProxyAddresses'; E={$($_.proxyAddresses -split ", ") -join "`n"}}
        } #try
        catch {
            Write-Host "$Group does not exists" -BackgroundColor DarkRed
        }
    } | Out-File $TempFile #foreach
} #Process
end {
    Get-Content -Path $TempFile
}

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

Go Back

Comment