Quantcast
Channel: PowerShell Daily » Name
Viewing all articles
Browse latest Browse all 3

Change Outlook Account Settings

$
0
0

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"

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images