Change Outlook Account Settings

As you may know all Outlook account settings for user are stores in registry and it is hard to change some settings for big amount of users (for my example – 500).

One day I have received the task to change mail server name and apply tls encryption for all our corporate users. I’ve found an interesting powershell script for changing user account settings locally. And that’s what I needed is to copy all necessary files to user’s PC and make changes in account settings.

First of all you should download this snapin (http://psoutlookmanager.codeplex.com) and use two dll’s from it which will allow to add snapin to your script (OutlookAccountManager.dll and OutlookAccountManagerPS.dll)

After that make a OutlookAccountManager.reg file (after adding it to registry snapin will be installed – the same thing as:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
cd

install OutlookAccountManagerPS.dll

)

with this content:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\OutlookAccountManagerSnapIn]
"PowerShellVersion"="2.0"
"Vendor"="Alessandro Pilotti"
"Description"="Provides Outlook account management cmdlets"
"VendorIndirect"="OutlookAccountManagerSnapIn,Alessandro Pilotti"
"DescriptionIndirect"="OutlookAccountManagerSnapIn,Provides Outlook account management cmdlets"
"Version"="1.0.0.0"
"ApplicationBase"="C:\\Documents and Settings\\All Users\\OutlookAccountManager"
"AssemblyName"="OutlookAccountManagerPS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78530d5fb3fc68b4"
"ModuleName"="C:\\Documents and Settings\\All Users\\OutlookAccountManager\\OutlookAccountManagerPS.dll"

After these step it is needed to copy that dlls locally to use it. Follow this code to copy them locally (OutlookAccountManager.ps1):

$Sour = "\\domain\netlogon\Outlook.Profile\Files"
$Dest = $env:ALLUSERSPROFILE+"\OutlookAccountManager"
if (!(Test-Path "$Dest\OutlookAccountManagerPS.dll"))
    {
    Copy-Item $Sour -Destination $Dest -Recurse
    }

And finally it’s possible to make the essential script which changes all necessary outlook account settings (Outlook.Profile.ps1):

Add-PSSnapin OutlookAccountManagerSnapIn
$profile = Get-MAPIAccount "Outlook" | where-object {!$_.IsExchange}
$profile | foreach `
    {
    if (($_.OutgoingServer = "192.168.100.1") `
    -or ($_.IncomingServer = "192.168.100.1") `
    -or ($_.OutgoingServer = "mail.mail.com") `
    -or ($_.IncomingServer = "mail.mail.com"))
        {
        $_.OutgoingServer = "mail.new.com"
        $_.IncomingServer = "mail.new.com"
        $_.OutgoingSSL = $True;
        $_.OutgoingPort = 465;
        Set-MAPIAccount $_;
        }
    }
Remove-PSSnapin OutlookAccountManagerSnapIn

As you can see there are some of ifs. They are needed only for finding that outlook accounts which are related to our corporate network. It’s not changing that accounts which contain other mail servers.

And finally it is needed to put as startup scripts for whole domain following strings:

powershell.exe -command "\\domain\netlogon\Outlook.Profile\OutlookAccountManager.ps1"
regedit.exe /s "\\domain\netlogon\Outlook.Profile OutlookAccountManager.reg"

and logon scripts:

powershell.exe -command "\\domain\netlogon\Outlook.Profile\Outlook.Profile.ps1"
bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top

3 Responses to “Change Outlook Account Settings”

  1. Julienco says:

    Hello,

    Has anyone already use this API on 64bits machine ?
    I got a lot of errors on this kind of environnement.

  2. use this code $_.OutgoingUseAuthentication = $true; and investigate further in Get-MAPIAccount and Set-MAPIAccount CmdLets

  3. levent says:

    This script will help me alot on my projec, but I will need some additions if its possible.
    May I also change and deploy outgoing server logon credentials to high amount of users. I will have a single account for smtp server login (mail@domain.com and pwd 123456 etc.)
    I am using my exchange server as internal-relay, 150 mail user is in organization and 750 user is on cpanel mail server. this is why I should change account settings for Cpanel users incoming server is Cpanel and outgoing server is exchange.

    Best Regards

    Thanx in advance.

Leave a Reply