Find Exchange Servers in the Local Active Directory Site using PowerShell
2015-05-21 16:51
399 查看
原文:http://mikepfeiffer.net/2010/04/find-exchange-servers-in-the-local-active-directory-site-using-powershell/
Using the Get-ExchangeServer cmdlet is the best way to get information about Exchange servers using PowerShell, but there may be times where you want to obtain this information without using the EMS cmdlets. For instance, you may be want to write a PowerShell
script that works with Exchange on a machine without the Exchange tools installed.
The following function uses an ADSI DirectorySearcher to search the current Active Directory site for Exchange 2010 servers.
Here is the output from running the above function:
As you can see we get the netbios name of the server, the FQDN and the roles value provided by the
msExchCurrentServerRoles attribute. The server roles can be determined by comparing the value to the table listed in
this technet article. The role values are defined as follows:
Mailbox Role – 2Client Access Role – 4Unified Messaging Role – 16Hub Transport Role – [b]32Edge Transport Role – 64
For example, you can see from the output that HC1 and HC2 both return a value of 36 for the server role. Given that 4 + 32 = 36, we know HC1 and HC2 are running both the HUB and CAS roles. We can also see that MB1 and MB2 are running only the Mailbox server
role, and litware-edge is running the edge role.
If you need to translate these role values, we can add the values and descriptions to a hash table:
And then use the following code to get the textual descriptions:
The output would look something like this:
Again, this code is no replacement for the Get-ExchangeServer cmdlet, but it could be useful if you need to grab this information without EMS cmdlets. In an upcoming post, I’ll provide a useful (hopefully) example of how you may use the Get-ExchangeServerinSite
function.
原文:http://mikepfeiffer.net/2010/04/find-exchange-servers-in-the-local-active-directory-site-using-powershell/
Using the Get-ExchangeServer cmdlet is the best way to get information about Exchange servers using PowerShell, but there may be times where you want to obtain this information without using the EMS cmdlets. For instance, you may be want to write a PowerShell
script that works with Exchange on a machine without the Exchange tools installed.
The following function uses an ADSI DirectorySearcher to search the current Active Directory site for Exchange 2010 servers.
Function Get-ExchangeServerInSite { $ADSite = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite] $siteDN = $ADSite::GetComputerSite().GetDirectoryEntry().distinguishedName $configNC=([ADSI]"LDAP://RootDse").configurationNamingContext $search = new-object DirectoryServices.DirectorySearcher([ADSI]"LDAP://$configNC") $objectClass = "objectClass=msExchExchangeServer" $version = "versionNumber>=1937801568" $site = "msExchServerSite=$siteDN" $search.Filter = "(&($objectClass)($version)($site))" $search.PageSize=1000 [void] $search.PropertiesToLoad.Add("name") [void] $search.PropertiesToLoad.Add("msexchcurrentserverroles") [void] $search.PropertiesToLoad.Add("networkaddress") $search.FindAll() | %{ New-Object PSObject -Property @{ Name = $_.Properties.name[0] FQDN = $_.Properties.networkaddress | %{if ($_ -match "ncacn_ip_tcp") {$_.split(":")[1]}} Roles = $_.Properties.msexchcurrentserverroles[0] } } }
Here is the output from running the above function:
As you can see we get the netbios name of the server, the FQDN and the roles value provided by the
msExchCurrentServerRoles attribute. The server roles can be determined by comparing the value to the table listed in
this technet article. The role values are defined as follows:
Mailbox Role – 2Client Access Role – 4Unified Messaging Role – 16Hub Transport Role – [b]32Edge Transport Role – 64
For example, you can see from the output that HC1 and HC2 both return a value of 36 for the server role. Given that 4 + 32 = 36, we know HC1 and HC2 are running both the HUB and CAS roles. We can also see that MB1 and MB2 are running only the Mailbox server
role, and litware-edge is running the edge role.
If you need to translate these role values, we can add the values and descriptions to a hash table:
$role = @{ 2 = "MB" 4 = "CAS" 16 = "UM" 32 = "HT" 64 = "ET" }
And then use the following code to get the textual descriptions:
foreach ($server in Get-ExchangeServerinSite) { $roles = ($role.keys | ?{$_ -band $server.roles} | %{$role.Get_Item($_)}) -join ", " $server | select Name, @{n="Roles";e={$roles}} }
The output would look something like this:
Again, this code is no replacement for the Get-ExchangeServer cmdlet, but it could be useful if you need to grab this information without EMS cmdlets. In an upcoming post, I’ll provide a useful (hopefully) example of how you may use the Get-ExchangeServerinSite
function.
相关文章推荐
- Using Ldp.exe to Find Data in the Active Directory
- 解决mvn install问题Failure to find ** was cached in the local repository
- open files in a directory and then find someword in the text tcl tk
- [TypeScript] Find the repeated item in an array using TypeScript
- Accessing the active space or layout in an AutoCAD drawing using .NET
- Using the ASP.NET 2.0 ReportViewer in Local Mode
- Non-resolvable import POM: Failure to find Dalston.RC1 in was cached in the local repository
- SYBASE备份报错:Can't open a connection to site 'SYB_BACKUP',see the error log file in the ASE directory
- Lists all entries in the Active Directory
- How-to find the SQL that using lots of temp tablespace in Oracle
- Using the ASP.NET 2.0 ReportViewer in Local Mode
- Orlmite配置文件writeConfigFile出现Could not find raw directory which is typically in the res directory
- Searching the Active Directory with PowerShell
- Failure to find xxx in xxx was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ xxx
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)
- PowerShell to Create New Mailboxes in the smallest database in Exchange 2007 Organization
- Matrix and linear algebra in F#, Part IV: profile your program, find the bottleneck and speed it up: using matrix multiplication as an example[z]
- Authenticate a user against the Active Directory using the user ID and password
- using the masterpage from your site in custom _layouts pages
- Given a number,find the next higher number using the same digits in the number.