The command below finds all Exchange servers registered in AD (as far as I have understood) but if I have several servers, one with the Mailbox server role and one Edge transport role, how do I figure out which of these have the Mailbox server role?
Get-ADObject -LDAPFilter “(objectClass=msExchExchangeServer)” –SearchBase “CN=Configuration,DC=domainname,DC=net” | Select-Object name
Instead of the AD cmdlets, assuming you are using Exchange 2010 or newer, use the Exchange Management Console with the following command:
Get-ExchangeServer | Where-Object {$_.IsMailboxServer}
For earlier versions of exchange I’m not sure what AD attribute would identify a back-end server (Exch 2003 for example). But if you look through the attribute editor you may be able to find an attribute to filter by.
Thanks. I am using a newer than 2010 and the command worked in Exchange Management Console.
Is it possible to use PSSession to use Exchange Management Console on a client machine? The reason I am asking is that I am working on a script to make new users and I want the script to find the mail server with the Mailbox server role by itself. If I want to share it later it will be easier to use for anyone else.
You can use implicit remoting to connect to exchange and manage exchange remotely through powershell without having the management tools installed.
http://blogs.technet.com/b/ptsblog/archive/2011/09/02/single-seat-administration-of-exchange-2010-using-powershell-implicit-remoting.aspx
There are some caveats to using implicit remoting. Mainly due to deserialization of objects as they are passed between client and server. The main ones I can recall are:
- Script methods on object properties will not be available. eg. ToKB()/ToMB()/ToGB() is not available to convert size properties like seen on mailbox statistics
- Piping from one cmdlet to another requires the use of ForEach-Object and explicit definition of values for parameters as objects returned to your console via an implicit remoting command are deserialized and therefore are not of the same object type as what would be expected by the down-stream cmdlet.
I think your best bet is to install management tools on whichever box you will be running the provisioning script from. There area host of cmdlets that will help you out on this journey.
Remember in Exch2010 and later the database/server isn’t a 1:1 relationship thanks to DAGs. it’s often easier to simply target the DB directly with new-mailbox -database “blah” and move on.
You can also use the “isexcludedfromprovisioning” flag on the individual Database to block automatic placement on databases you feel are “full” or you are simply trying to avoid accounts from being made on. Finally an RBAC filter can hide different databases from different teams if you plan on having different groups managing unique server groups, for example the HelpDesk team for “wingnutz LLC” can only see/place users on the wingnutz database … no matter what server it’s hosted on.
As far as I can see i am using implicit remoting but it does not seem to work. When I run the below code I get an error stating that the term Get-ExchangeServer does not exist. It is possible to run the command Get-Mailbox in the script so I know the session connected to the remote server. When I run the command in the Exchange Management Shell on the server I get the response I need.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http:///PowerShell/ -Authentication Kerberos
Import-PSSession $Session
Get-ExchangeServer | Where-Object {$_.IsMailboxServer -Eq $true } | Select Name | Sort-Object
Is it possible to solve this?
Are you using different credentials when connecting to the exchange server? This seems the most likely cause to me. The credentials you use to connect to the Exchange server have appropriate rights and the user account you are logged on to your workstation with (where you’re initiating an implicit remoting session from) does not have appropriate access.
Try adding -Credential to your New-PSSession command to connect with the same credentials you use when RDP-ing to the exchange server. Like this:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http:///PowerShell/ -Authentication Kerberos -Credential $(Get-Credential "domain\user")
Import-PSSession $Session
Get-ExchangeServer | Where-Object {$_.IsMailboxServer -Eq $true } | Select Name | Sort-Object
Thanks for your help. It worked after I removed -Authentication Kerberos from your suggestion. I added some code that finds the exchange-servers in AD and runs the command on the first one found. It may not be the smoothest code but it makes the code more versatile and easier to share. This is going to be part of a larger code/script that will find the DomainName and TopLevel automaticly as well. It looks looks this:
#This block finds the Exchange-server in AD, connects to one of them and gets the name of the MailBox-server.
$FindMailServer=(Get-ADObject -LDAPFilter "(objectClass=msExchExchangeServer)" –SearchBase "CN=Configuration,DC=,DC=").name[0]
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$FindMailServer/PowerShell/ -Credential $(Get-Credential "domain\user")
Import-PSSession $Session
$MailBoxServer=Get-ExchangeServer | Where-Object {$_.IsMailboxServer -Eq $true } | Select Name | Sort-Object
$MailBoxServer.name