I have a series of macros that can bulk change contacts, but using a macro is not the only way to bulk change contacts. You can make the same changes using a PowerShell script.
Any Outlook field can be manipulated using PowerShell. This script sample changes the File As and Email Display Name field of the Contacts in the Default Contacts folder to match the Full Name field.
To use, right-click on the Start menu in Windows 10 and click on the Windows PowerShell entry. Paste the entire script in the PowerShell window and press Enter.
Note: This PowerShell script will not work with the Windows Store version of Office. You'll need to use the macro version if you have the Windows store version of Office installed.
Like the Bulk Change Email Display Name Format macro, the PowerShell version uses the default FileAs format or a custom format. Use the same method to change other Outlook fields.
Change the Email Display Name field
This PowerShell changes the email display name field for Email1. You can tweak it to change the display names for Email2 and Email3 as well. You can use the macro on the default folder or comment out (add a # to the beginning of the line) the default folder line, remove the comment block (#) from the selected folder line and run it on the selected folder.
$olApp = new-object -comobject outlook.application $namespace = $olApp.GetNamespace("MAPI") # Default Contacts folder $Contacts = $namespace.GetDefaultFolder(10) # Uses current folder #$Contacts = ($olApp.ActiveExplorer()).CurrentFolder foreach ($Contact in $Contacts.Items) { # Change only contacts with SMTP address if ($Contact.Email1Address -like "*@*") { # Uncomment the file as format you want #Lastname, Firstname (Company) format # $newFileAs = $Contact.FullNameAndCompany #Firstname Lastname format # $newFileAs = $Contact.FullName #Lastname, Firstname format # $newFileAs = $Contact.LastNameAndFirstName #Company name only # $newFileAs = $Contact.CompanyName #Companyname (Lastname, Firstname) # $newFileAs = $Contact.CompanyAndFullName # Custom format $newFileAs = $Contact.CompanyName + " (" + $Contact.FullName + ")" # Comment out lines if you don't want to change the field # $Contact.FileAs = $Contact.CompanyAndFullName $Contact.Email1DisplayName = $newFileAs $Contact.Save() } } $olApp.Quit | Out-Null [GC]::Collect()
Swap First and Last Name fields
To swap fields, you need to add the current field value to a variable then add them to the other field. Don't forget to Save the contact!
The macro version of this script is at Macro to Swap First and Last Name Fields
$olApp = new-object -comobject outlook.application $namespace = $olApp.GetNamespace("MAPI") # Default Contacts folder $Contacts = $namespace.GetDefaultFolder(10) # Uses current folder #$Contacts = ($olApp.ActiveExplorer()).CurrentFolder foreach ($Contact in $Contacts.Items) { $curFirstName = $Contact.FirstName $CurLastName = $Contact.lastname $Contact.FirstName = $CurLastName $Contact.LastName = $curFirstName $Contact.Save() } $olApp.Quit | Out-Null [GC]::Collect()
Saving PowerShell Scripts
If you want to save the script as a .ps1 file, paste it into Notepad and save it with the extension .ps1. To open it in the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell IDE when the PowerShell app is found. Paste the script in the editing window.
To use it, you need to allow local scripts by running this command:
Set-ExecutionPolicy RemoteSigned
To run your saved .ps1 file, right-click on the script and choose Run with PowerShell.
Hi Diane
Just checked over a few of your Powershell suggestions to amend Outlook email accounts, either names etc I found them very interesting
I would really like something that I can add as an attachment to a number of junk emails that have been sent to me- some very unpleasant- I just want them to click on it and it will remove my name/email from their contacts/list. Please could you help me wit this
You don't want to reply to junk mail - that validates your address and you will get more junk.
If its newsletters you signed up for, it is safe to unsubscribe - but never for unsolicited email.