Alan's sysadmin Blog

Working smarter not harder

Archive for the ‘PowerShell’ Category

Unable to Connect to Exchange Management Shell after SP2 installation

Posted by Alan McBurney on September 12, 2012

After patching a number DAG nodes with SP2 I was unable to open the EMC from any of the mailbox servers.

The follow error was displayed

SNAGHTML737be47

To resolve this issue I downloaded the Exchange Management Console Troubleshooter Tool EMTShooter

After running the tool it found an error and displayed the following

image

After reading through the possible solutions I discounted options 2 & 3 as these had already been investigated and the settings were correct.

So with that I settled on option 1.

After examining the GlobalModules of C:\Windows\System32\Inetsrv\config\ApplicationHost.config I could see that the entry for WSMan was indeed missing

image

I added the entry and closed the file

image

Refresh the EMC and viola, good as new.

image

Posted in EMC, Exchange 2010, PowerShell | Tagged: , , , , , | Leave a Comment »

Rebuilding an Exchange DAG

Posted by Alan McBurney on April 10, 2012

Recently I’ve been working with a customer where their DAG has been misbehaving.

The DAG was stretched between 2 AD sites. There were multiple issues with cluster resources in addition to the PAM (Primary Active Manager) not failing over properly

After looking at it for a few hours I decided that the best course of action would be to rebuild the DAG

The following are the steps required in order to remove the DAG and rebuild it

  • Remove All Database Copies from the DAG

Remove-MailboxDatabaseCopy “DBName\ServerToRemove” –Confirm:$False

  • Turn off DataCenter Activation Mode

Set-DatabaseAvailabilityGroup -Identity DAG1 -DatacenterActivationMode Off

  • Remove the MailboxServers from the DAG

Remove-MailboxDatabaseAvailabilityServer DAG1 –MailboxServer ServerToRemove

Be sure to allow time for replication to occur between executing commands

  • Recreate the DAG

New-DatabaseAvailabilityGroup -Name DAG1 –WitnessServer “WitnessServer” -WitnessDirectory D:\DAG1  -DatabaseAvailabilityGroupIpAddresses 192.168.100.100,192.168.101.100

  • Add the servers back into the DAG

Add-DatabaseAvailabilityGroupServer -Identity DAG1 –MailboxServer “SourceMBXServer”
repeat this command for all servers that you wish to add

  • Enable Database Activation Mode

Set-DatabaseAvailabilityGroup -Identity DAG1 -DatacenterActivationMode DAGOnly

  • Finally Add the mailboxdatabase copy server

Add-MailboxDatabaseCopy –Identity DBName -MailboxServer MBXServerToAdd -ActivationPreference 2

  • Finally we can test the Primary Active Manager Failover

Cluster.exe DAG1.DOMAIN.LOCAL Group “Cluster Group” /MoveTo:PassiveServerNode

Posted in Exchange 2010, PowerShell | Tagged: , , , , , , , | Leave a Comment »

Reseed failed DAG database copies

Posted by Alan McBurney on September 16, 2011

I have been working with a customer that has a large number of Exchange databases and wishing to to protect these with a DAG solution.

A multi node DAG had been built for the customer and one of the nodes was being problematic when it came to the initial seeding of the database.
The databases would initially seed fine, however as soon as they finished the DB’s momentarily reported “Healthy” before changing status to “FailedandSuspended”

I tried a number of fixes for this including manually copying log and catalog files, however nothing seemed to work. Then in true Microsoft fashion a reboot of the server resolved the issues and the databases seeded properly. After running an update against a DB it’s status remained “Healthy”

As previously stated the customer had a large number of DB’s that were being replicated so I resorted to the Shell to fix the remainder of the DB’s that were “FailedandSuspended”

The following command was used to bring the remainder of the DB’s back to a healthy state

Get-MailboxDatabaseCopyStatus –Server (MBXServerName) | Where-Object {$_.Status –eq “FailedandSuspended”} | Update-MailboxDatabaseCopy –DeleteExistingFiles –SourceServer (SourceMBXServerName)


Job done :)

Posted in Exchange 2010, PowerShell | Tagged: , , , | Leave a Comment »

Configuring Exchange 2010 Archive Mailboxes

Posted by Alan McBurney on September 13, 2011

I’ve been doing a large migration lately which has involved configuring all users with an Archive mailbox, setting the retention policy and moving items past retention into the Archive databases.

The users primary mailbox would reside on SAS disk while the archive databases were being stored on cheaper SATA disk.

The “Default Archive Policy”  of moving items older than 2 years into the Online Archive would be used

The high level steps for this were as follows.

  1. Enable the users for archive
  2. Setting the archive database and enabling the retention policy
  3. Testing move of mail items past retention into the Archive database

As there were several thousand users on the system the only sensible way to achieve this was through the shell.

The users were already broken in 14 databases so naturally I approached this on a per database.

The following shell commands were used

Get-MailboxDatabase (DBName) | Get-Mailbox | Enable-Mailbox –Archive

Get-MailboxDatabase (DBName) | Get-Mailbox | Set-Mailbox –ArchiveDatabase (ArchiveDBName) –RetentionPolicy “Default Archive Policy”

Get-MailboxDatabase (DBName) | Get-Mailbox | Start-ManagedFolderAssistant

The Managed Folder Assistant runs nightly, however I used the above command to kick the process off immediately and verify that data was indeed moving to the new Archive DB

Posted in Exchange 2010, PowerShell | Leave a Comment »

How to view Whitespace in Exchange 2010 Databases

Posted by Alan McBurney on September 12, 2011

With older versions of Exchange admins would use the 1221 EventID to see how much whitespace was available in each database.

With Exchange 2010 EventID 1221 is no longer used.

Admins now can query the database directly with the following PowerShell command to see the whitespace in each Database

Get-MailboxDatabase -Status | FT Name, AvailableNewMailboxSpace

Posted in Exchange 2010, PowerShell | Leave a Comment »

Recreate arbitration accounts in Exchange 2010

Posted by Alan McBurney on April 14, 2011

Following a DR situation with a customer where I had to disable the arbitration accounts in order to remove a database, I was able to sucessfully restore these accounts to their prior state once the DB was restored with the help of Martin’s blog post

Posted in Exchange 2010, PowerShell | Leave a Comment »

Script to configure Internal & External URL’s for Exchange 2010

Posted by Alan McBurney on August 25, 2010

**Update**

Stale has updated his script over at msunified.net to break the dependancy on the CASArray. I have used the script a few times and can highly recommend it. Its definitely a must have for your Exchange 2010 toolbox

——————–

*Update

I no longer recommend using this script as the CAS Array should not use the same name as Internal\External namespace. this is due to the fact the when using RPC over HTTPS a delay of 30 seconds will  occur when connecting to the mailbox as the default transport mechanism of TCP\IP is used when namespaces  are identical.

You can of course use this script and then delete the CAS Array and recreate it with a different name.

——————–

When working with Exchange 2007 Exchange ninjas has a great script for configuring all VDirs on Exchange 2007  which can be found here.

However now that 2010 is here I was looking for a new script. I found this excellent script by Ståle Hansen. One thing to be aware of is that the script relies on detection of an Exchange Client Access Array which can and imo should be set even when using a single server.

Script can be found here

Posted in Exchange 2010, Outlook, PowerShell | 2 Comments »

Change default gateway on clients with static IP’s using PowerShell

Posted by Alan McBurney on July 29, 2010

Recently when working on a project I need to change the gateway on a bunch of clients that had static IPs.

This PowerShell Script did the job

——-Begin Script———-

function Set-Gateway  {

#Get NICS via WMI

$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter “IPEnabled=TRUE”

foreach($NIC in $NICs) {$Gateway = “192.168.0.254″

$NIC.SetGateways($Gateway)

}

}

function Get-FileName {

$computer = Read-Host “Please specify the location of the file containing the computer names”

return $computer

}

$f = Get-FileName

Get-Content $f | foreach {Set-Gateway}

——-End Script———-

Posted in PowerShell, Windows Servers | Tagged: | 2 Comments »

Granting multiple users access to specific computers using RWW in SBS 2008

Posted by Alan McBurney on August 14, 2009

While working on an SBS 2008 migration I was faced with having to grant 60 users access to only Terminal Servers in the corporate network when using Remote Web Workplace

Powershell and Quest Active Roles to the rescue again.

The following script sets the msSBSComputerUserAccessOverride attribute to the desired computer

[PS] C:\> Get-QADUser | Where {$_.ParentContainerDN -eq “OU=MyOU,DC=Domain,DC=Local”} | Set-QADUser –ObjectAttributes @{msSBSComputerUserAccessOverride = ”S:1:3:CN=MyTerminalServer, OU=SBSServers, OU=Computers, OU=MyBusiness, DC=Domain, DC=Local”}

Posted in PowerShell, SBS | Tagged: , , | Leave a Comment »

PowerShell Script to hide users from GAL

Posted by Alan McBurney on August 13, 2009

This script using Quest Active Roles will check Active Directory for disabled accounts and then hide these from the Exchange GAL.

[PS] C:\> Get-QADUser | Where-Object { $_.AccountisDisabled -eq “TRUE” -and $_.MailNickName -like “*” } | Set-QADUser -ObjectAttributes @{msExchHideFromAddressLists=”TRUE”;ShowInAddressBook=”"}

Posted in Exchange 2010, PowerShell | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 153 other followers