How to Fully Re-Install Exchange On SBS 2008

(Note: this will remove from your environment so you will have to re-create\attach mailboxes)

Recently I had a situation where I needed to fully remove and re-install Exchange on SBS2008, here is the process I was able to develop using technet, a couple blogs and trial an error

Prep For uninstall

Run Exchange Management Shell as administrator

Answer A or Y to all PS Prompts

  1. Remove all mailboxes
    • Get-mailbox | disable-mailbox
  2. Remove-receive Connectors
    • Get-recieveconnector | remove-recieveconnector
    • Get-sendconnector | remove-sendconnector
  3. Remove Public Folder and oab
    • Get-offlineaddressbook | remove-offlineaddressbook
    • Adsiedit.msc – > Connect to : Configuration ->
    • Configuration -> Configuration -> Services -> Microsoft Exchange -> First Org.. -> administrative Groups -> Exchange Admin Group.. -> Servers -> Servername -> Information Store -> Second Information Store -> Right Click and delete “Public Folder Databas


  1. Start -> control -> programs and features -> Microsoft Exchange -> uninstall -> uncheck all roles ->
  2. Rename Databases Folders
    1. From Powershell > move c:\program files\Microsoft\Exchange Server\mailbox” c:\program files\Microsoft\Exchange Server\mailbox.old”

Re-Install Exchange

  1. Download Exchange2007 SP1 (E2K7SP1EN64.exe)
  2. Create a registry value to use with Windows SBS 2008 Disc 2 (Component Technologies for Server Repair) and Microsoft Exchange Server 2007 by doing the following:
    1. Open Registry Editor.image
    2. On the User Account Control page, click Continue.
    3. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\461C2B4266EDEF444B864AD6D9E5B613\SourceList\Media.
    4. Create a new string value named MediaPackage: Right-click Media, click New, click String Value, in Name type MediaPackage, and then press ENTER.
    5. Double-click MediaPackage, in Edit String, in Value data, type \CMPNENTS\Exchange12\, and then click OK.
    6. Close Registry Editor.
  3. Run the Setup from the extracted Directory, Rt click Setup and Run As Administrator
  4. Click Step 4: Install Microsoft Exchange Server 2007 Sp1
  5. Next -> Select Mailbox\CAS\HUB
  6. Enter Org Name (Default is “First Organization”)
  7. Next

SBS Roles Reinstall Script

  1. Run Windows PowerShell commands by doing the following:
    1. Copy and paste the following cmdlets into a text file: (Run Notepad as administrator)
        $LocalServerName = hostname$ActiveSyncMailboxName = “Windows SBS Mobile Mailbox Policy” + ” ” + $LocalServerName

        $OABVDir = $LocalServerName + “\OAB (SBS Web Applications)”

        $OAB = Get-OfflineAddressBook | Select-Object -Property Name

        $strDomainDNS = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name

        $DomainAdmins = $strDomainDNS + “\Domain Admins”

        $OrgName = Get-OrganizationConfig | Select-Object -Property DistinguishedName

        $DefaultExchangeCertificate = “CN=” + $LocalServerName

        Get-ExchangeCertificate | Where { $_.Subject -eq “$DefaultExchangeCertificate” } | ForEach { Remove-ExchangeCertificate -Thumbprint $_.Thumbprint }

        Set-ForeignConnector “Windows SBS Company Web Connector $LocalServerName” -SourceTransportServers $LocalServerName

        REG ADD HKLM\SYSTEM\CurrentControlSet\Services\MSExchangeIS\ParametersSystem /v “Disable MAPI Clients” /t REG_SZ /d 0.0.0-5.3164.0

        Get-MailboxDatabase | Set-MailboxDatabase -OfflineAddressBook $OAB.Name -DeletedItemRetention “30.00:00:00”

        Get-StorageGroup | Set-StorageGroup -CircularLoggingEnabled 1

        Remove-OWAVirtualDirectory -Identity “Owa (Default Web Site)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Exadmin (Default Web Site)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Exchange (Default Web Site)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Exchweb (Default Web Site)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Public (Default Web Site)” -Confirm:$false

        Remove-WebServicesVirtualDirectory -Identity “EWS (Default Web Site)” -Confirm:$false

        Remove-ActiveSyncVirtualDirectory -Identity “Microsoft-Server-ActiveSync (Default Web Site)” -Confirm:$false

        Remove-OabVirtualDirectory -Identity “OAB (Default Web Site)” -Force:$true -Confirm:$false

        Remove-UMVirtualDirectory -Identity “UnifiedMessaging (Default Web Site)” -Confirm:$false

        Remove-AutodiscoverVirtualDirectory -Identity “Autodiscover (Default Web Site)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Exadmin (SBS Web Applications)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Exchange (SBS Web Applications)” -Confirm:$false

        Remove-OWAVirtualDirectory -Identity “Public (SBS Web Applications)” -Confirm:$false

        New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2007” -ExternalAuthenticationMethods Fba

        Set-OWAVirtualDirectory -InternalUrl “https://sites/owa/” -ClientAuthCleanupLevel “Low” -LogonFormat “UserName” -DefaultDomain $strDomainDNS -Identity “Owa (SBS Web Applications)”

        New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000” -VirtualDirectoryType “Exadmin” -ExternalAuthenticationMethods Fba

        New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000” -VirtualDirectoryType “Mailboxes” -ExternalAuthenticationMethods Fba

        New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000” -VirtualDirectoryType “Exchweb” -ExternalAuthenticationMethods Fba

        New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000” -VirtualDirectoryType “PublicFolders” -ExternalAuthenticationMethods Fba

        New-WebServicesVirtualDirectory -WebsiteName “SBS Web Applications” -InternalUrl “https://Sites/EWS/Exchange.asmx” -basicauthentication 1 -windowsauthentication 1

        New-ActiveSyncVirtualDirectory -WebsiteName “SBS Web Applications” -InternalUrl “https://Sites/Microsoft-Server-ActiveSync” -ExternalAuthenticationMethods Basic -InternalAuthenticationMethods Basic

        New-OabVirtualDirectory -WebsiteName “SBS Web Applications” -InternalUrl “https://Sites/OAB”

        Set-OabVirtualDirectory -PollInterval “30” -Identity “oab (sbs web applications)”

        New-UMVirtualDirectory -WebsiteName “SBS Web Applications” -InternalUrl “https://Sites/UnifiedMessaging/Service.asmx”

        New-AutodiscoverVirtualDirectory -WebsiteName “SBS Web Applications” -InternalUrl “https://Sites/Autodiscover/Autodiscover.xml” -BasicAuthentication 1 -WindowsAuthentication 1

        Set-ClientAccessServer -Identity $LocalServerName -AutoDiscoverServiceInternalUri “https://sites/Autodiscover/Autodiscover.xml”

        Set-OfflineAddressBook $OAB.Name -VirtualDirectories $OABVDir -Versions Version2,Version3,Version4 -PublicFolderDistributionEnabled:$True

        iisreset /noforce

        cd $env:windir\system32\inetsrv

        .\appcmd.exe unlock config “-section:system.webserver/security/authentication/windowsauthentication”

        .\appcmd.exe set config “SBS Web Applications/ews” “-section:windowsAuthentication” “-useKernelMode:False” /commit:apphost

        .\appcmd.exe set config “SBS Web Applications/AutoDiscover” “-section:windowsAuthentication” “-useKernelMode:False” /commit:apphost

        .\appcmd.exe set config “SBS Web Applications/oab” “-section:windowsAuthentication” “-useKernelMode:False” /commit:apphost

        .\appcmd.exe set site “Default Web Site” /Bindings:http/*:80:

        .\appcmd.exe start site “Default Web Site”

        .\appcmd.exe start site “SBS Web Applications”

    2. Name the text file sbsAllrolereinstall.ps1, and then save it in C:\windows\system32.
    3. Open Exchange Powershell: Click Start, click All Programs, click Microsoft Exchange Server 2007, right-click Exchange Management Shell, and then click Run as administrator.
    4. On the User Account Control page, click Continue.
    5. In Exchange Management Shell, type .\sbsAllrolereinstall.ps1, and then press ENTER.
    6. Type Y to confirm the action, and then press ENTER.
    7. Close Exchange Management Shell.
  2. Update the settings in the Internet Information Services (IIS) Manager by doing the following:
    1. Click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.
    2. On the User Account Control page, click Continue.
    3. Expand the name of your Windows SBS 2008 server, and then expand Sites.
    4. Click Default Web Site, and then click Start.
    5. Expand SBS Web Applications, and then click OAB.
    6. In OAB Home, double-click SSL Settings.
    7. Select Require SSL and Require 128-bit SSL, and then click Apply.
  3. To send e-mail messages to the Internet, run the Fix My Network Wizard by doing the following:
    1. Open the Windows SBS Console.
    2. On the navigation bar, click Network, and then click Connectivity.
    3. In the task pane, click Fix my network.
    4. Follow the instructions in the wizard. You can click each potential problem that the wizard lists to get more information about the problem. To recreate the default Send and Receive connectors to re-establish mail flow, select Exchange SMTP connectors are invalid.
  4. Rerun the Internet Address Management Wizard to associate the new virtual directories with the correct external URL.
  5. If your server uses a trusted certificate, you must also run the Add Trusted Certificate Wizard.
  6. You may end up with the exchange saying its not license you can register Exchange on SBS with this tool.
      Activate Exchange

Info gathered from

Rahman® Reviews
List of SBS Recovery options.


8 thoughts on “How to Fully Re-Install Exchange On SBS 2008

  1. Thanks for the info first up…
    having execution issues with the script.

    Incomplete string token.
    At C:\Windows\System32\sbsAllrolereinstall.ps1:55 char:117
    + New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exch
    ange2003or2000? -VirtualDirectoryType “E <<<< xadmin" -ExternalAuthenticationMe
    thods Fba

    the script stops here – any ideas – any help would be appriciated


    • it looks like maybe in the copy past the quote got messed up, I have seen that happen with pulling off a blog before though havent seen it yet on this one.

      I think you may just need to fix the quote where its a ? change to ”
      New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000? -VirtualDirectoryType “Exadmin” -ExternalAuthenticationMethods Fba

      in short go through and verify that what is in the script matches txt on the post. also replace the ” after the 2000.

      also you dont HAVE to run it as a script you can run 1 line at a time, that way you see the results of each.

  2. Hi,

    I know this is an old guide but I’m hoping you can help with your script, I am getting the following error:

    Incomplete string token. At C:\Windows\System32\sbsALLrolereinstall.ps1:57 char:117 + New-OWAVirtualDirectory -WebsiteName “SBS Web Applications” -OwaVersion “Exchange2003or2000” -VirtualDirectoryType “M <<<< ailboxes" -ExternalAuthenticationMethods Fba

    Any ideas?


    • Based on your reply it looks like a space may have been inserted in the -virtualdirectorytype “Mailboxes” maybe retype quotes and mailboxes. Some times the text doest copy correctly

      • Hi,

        Thanks for getting back to me – I have tried re-typing this part I wonder if there is another part of the script that has an issue as I had some problems with characters when pasting from wordpress.

        Are you able to stick the original working script into pastebin or something for me?

        The full script I am using is here:

        any help would be greatly appreciated

      • sorry for the late reply, things have been a little nuts lately.

        so I took a look at the link you provided and it looks like you have “&#8221” throughout the script, I think removing those (not sure where they came from) should resolve.
        also I pasted the original txt to pastebin as requested.

        Be sure you are running this on the correct version of exchange\SBS as vdirs change from version to version.

  3. No probs,

    Ah must of been something that happened when copying it,

    I’ve just run the one from pastebin, success! thank you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s