scripts

All posts tagged scripts

Some times it can be very usefull to automate things by creating a script. Of course you will first have to think if it is usefull to automate it or just decide to do it manually. Which option you chose is really hard to say but let’s say if you have to modify more then 50 items becomes very interested to use a script.

Exchange 2010 contains a few scripts, for example a script which let’s you configure Public Folder replica’s during a migration. All scripts can be found in the scripts directory. This directory can be found in the Exchange installation directory, for example  c:\Program Files\Microsoft\Exchange Server\V14\Scripts.

When you have opened the Exchange Management Shell (EMS) you can browse to it by typing cd $exscripts.

Here you will find a lot of scripts among them:

scriptdescriptionexample
AddReplicaToPFRecursive.ps1Script to add replica's of Public FoldersAdd PF replica's to an Exchange 2010 Server:
.\AddReplicaToPFRecursive.ps1 -server "Exchange 2003 Server" -TopPublicFolder "\" -ServerToAdd "Exchange 2010 Server"

Replicate the System Folders to an Exchange 2010 Server:
.\AddReplicaToPFRecursive.ps1 -TopPublicFolder "\NON_IPM_Subtree" -ServerToAdd "exchange2010
CheckInvalidRecipients.ps1Checks the environment for recipients with invalid characters.\CheckInvalidRecipients.ps1
MoveAllReplicas.ps1Moves all replicas away from a server. Necessary to remove a PF databaseMoves all replica's from the PF of Exchange 2003 to Exchange 2010:
.\MoveAllReplicas.ps1 -Server "Exchange Server 2003" -NewServer "Exchange Server 2010"

Besides these scripts a lot of ready-to-use scripts are offered by Microsoft and other bloggers. Personally I like the following two scripts:

  • fix-alias.ps1
  • ConvertFrom-LdapFilter.ps1
The first script can be used to fix aliases of mailboxes, mailcontacts and Public Folders. In some cases you will find that users might have an alias which contains incorrect characters. Starting from Exchange 2007 this isn’t allowed anymore. When you ignore this error you may see strange issues such as users dissapearing fromt the addresslist.
To prevent this kind of issues Microsoft has published a script. The script will give you the ability to search for specific characters and replace them. For example assume all aliasses will end with domain.com. By usinfg the fix-alias script using the following parameters domaim.com will be replaced by nothing:
 
fix-alias.ps1 -type mailbox -search “domein.com” -replace “”
 
The script has one limitation it can’t fix two errors. So if an allias contains an @ and a space the script will generate an error.
 
The second script is really usefull when you are migrating address lists or recipient policies. Normally you will have to manually rebuild both and convert the LDAP filter to an OPATH filter. When you will do this on a regular basis this will not be an issue but in most cases this is not what you do daily. In that case we can migrate them automatically by using the ConvertFrom-LdapFilter script. For example let’s say we have a recipient filter which is called support. This recipient policy will be applied to all employees of the support department and will add an e-mail address using the following domain support.domain.com. To convert this policy we can use the script as follows:
 
Set-EmailAddresspolicy Support -RecipientFilter (.\ConvertFrom-LdapFilter.ps1 $.LdapRecipientFilter)
 
As you can see there are enough scripts which can help you during a migration. The scripts mentioned above can be downloaded from the sites below:
 

Automate OWA IM Integration configuration – update

One of the options which was missing in the first edition of the script was to check if a certificate is self-signed or not. By default a self-signed certificate is installed on an Exchange CAS Server. The problem with this kind of certificates is that other servers won’t trust it.

If this is the case there are two options:

  • import the self-signed certificate on the other servers, in this case the Lync Front End;
  • install a valid certificate;

The first option is not  really the way you want to solve it but sometimes you don’t have another option.

Below the changes which have been made in the script:

  • check if a self-signed certificate is installed;
  • option to export the self-signed certificate;

If you got any tips or suggestions please leave a comment.

download prepare_owa_im.ps1 v1.1

Just as like Windows 2003 you need to add some components to Windows 2008 before you can install Exchange 2007. In this tutorial I will explain which need to be installed on which server and made some scripts for it, that’s far more easier then typing the commands one by one ;-).

When you gone prepare the AD for Exchange 2007 from a Windows 2008 server you first need to install the Active Directory Domain Services remote management tools. These tools make it possible to modify the schema and domain so that Exchange 2007 can be installed.

This can be done by executing the following script:

prepad4ex07.cmd

ServerManagerCmd -i RSAT
shutdown -r

After the installation of the tools the server will be  rebooted, this last thing is optional and is not always needed.

After the tools have been installed the next step is the CAS server. First we will install Powershell, this is a prerequisite for Exchange 2007. Next fase is installing several IIS components for the web applications such as: OWA and AutoDiscovery that will be hosted on the CAS.  When you are going to use Outlook Anywhere you also need to install the RPC over HTTP proxy, this will be done in the last step.

CASpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i Web-Server
ServerManagerCmd -i Web-ISAPI-Ext
ServerManagerCmd -i Web-Metabase
ServerManagerCmd -i Web-Lgcy-Mgmt-Console
ServerManagerCmd -i Web-Basic-Auth
ServerManagerCmd -i Web-Digest-Auth
ServerManagerCmd -i Web-Windows-Auth
ServerManagerCmd -i Web-Dyn-Compression
ServerManagerCmd -i RPC-over-HTTP-proxy
shutdown -r

After installing the components the server will be rebooted, this again is optional.

When the CAS server is prepared it’s time for the HUB server. If you want to use a script for it, it’s your own decission, this because just one component will be installed.

HUBpreex07.cmd

ServerManagerCmd -i PowerShell
shutdown -r

Now that the CAS and HUB server are prepared it’s time for the mailbox server.

MBpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i Web-Server
ServerManagerCmd -i Web-ISAPI-Ext
ServerManagerCmd -i Web-Metabase
ServerManagerCmd -i Web-Lgcy-Mgmt-Console
ServerManagerCmd -i Web-Basic-Auth
ServerManagerCmd -i Web-Windows-Auth
shutdown -r

As you can see IIS is installed besides Powershell. Exchange 2007 doesn’t use the SMTP and NNTP from IIS anymore, some other components do need IIS.

When you want to build a cluster of mailbox servers you will need to add an extra line of code to the script.

MBCpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i Web-Server
ServerManagerCmd -i Web-ISAPI-Ext
ServerManagerCmd -i Web-Metabase
ServerManagerCmd -i Web-Lgcy-Mgmt-Console
ServerManagerCmd -i Web-Basic-Auth
ServerManagerCmd -i Web-Windows-Auth
ServerManagerCmd -i Failover-Clustering 
shutdown -r

A next step could be installing the Edge Sync server.

Edgpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i ADLDS
shutdown -r

This script will install Powershell again, besides this Active Directory Lightweight Directory Services will be installed. This services have the same functionality as the Active Directory Application Mode (ADAM) as it was known in Windows 2003.

When you would like to use the auto attendant and voicemail functionality of Exchange 2007 you will need to install the UM role.

UMpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i Desktop-Experience
shutdown -r

This script will install the codecs for audio/video from the Windows Media Player.

When you have a dedicated management station it may be necessary to install the manegement tools on it. For this only Powershell and two IIS components are needed.

Mgpreex07.cmd

ServerManagerCmd -i PowerShell
ServerManagerCmd -i Web-Metabase
ServerManagerCmd -i Web-Lgcy-Mgmt-Console

I think we have talked about all the prerequisites for all rolles now. Below there are some links to some resources that contain extra information about this.

How to Install Exchange SP1 Prerequisites on Window Server 2008 or Vista
Speeding up installation of Exchange Server 2007 SP1 Prerequisites on Windows Server 2008

Today I did some experimentations with Powershell and created a script which creates mailcontacts from a CSV by importing the name, e-mail adddress and OU. When the mailcontact is created it will be added to a distributiongroup.

When you want to use the file you can just copy and paste it in Notepad and save is as a ps1 file. When you gone execute the command you need to give some parameters with it, it will looks like this:

adduserstodg.ps1 -CSVFile “c:\users.csv”

The easiest way is to put the file in the scripts directory from Exchange.

Complete script

Param(

[string] $CSVFile,

)

Import-CSV $CSVFile | ForEach-Object -Process {New-MailContact -Name $_.name -ExternalEmailAddress $_.email -OrganizationalUnit $_.ou}

Import-CSV $CSVFile | ForEach-Object -Process {Add-DistributionGroupMember -Identity DistibutionGroupName -Member $_.name}