Bulk update/edit mail contacts on exchange using powershell

Farrah Shawky 1 Reputation point
2021-07-23T16:08:10.147+00:00

Uploaded 700 contacts without realizing I had erased all white space from full name on csv file.

Since I also need to update details of existing external mail contacts on exchange (Name, FirstName, LastName, StreetAddress, City, StateorProvince, PostalCode, Phone, MobilePhone, Pager, HomePhone, Company , Title, OtherTelephone, Department, CountryOrRegion, Fax, Initials, Notes, Office, Manager),

can someone help me with writing a code/script for PowerShell to upload the correct csv to update contact details in bulk?

Microsoft 365 Publishing
Microsoft 365 Publishing
Microsoft 365: Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line. Publishing: The process of preparing, producing, and releasing content for distribution or sale.
618 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,522 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,711 Reputation points
    2021-07-23T19:13:54.06+00:00

    You can try something like this:

    # The CSV **must** contain these column names
    # They correspond to the parameter names for the Set-Contact cmdlet
    # IDENTITY, City, StateorProvince, PostalCode, Phone, MobilePhone, Pager, HomePhone, Company, Title, OtherTelephone, Department, CountryOrRegion, Fax, Initials, Notes, Office, Manager
    
    $contacts = Import-CSV c:\junk\data.csv
    $columns = $contacts[0].psobject.properties.names   # get the list of column names in the CSV
    
    # create the hash only once and populate the parameter names (but no values)
    $splat = @{}
    $columns |
        ForEach-Object{
            $splat[$_] = ""
        }
    
    ForEach($contact in $contacts){
        # load the hash with values each time
        $columns |
            ForEach-Object{
                $splat[$_] = $contact.$_
            }
        Set-Contact @splat
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.