设为首页 收藏本站
查看: 1609|回复: 0

Find Exchange Servers in the Local Active Directory Site using PowerShell

[复制链接]

尚未签到

发表于 2015-11-25 08:44:36 | 显示全部楼层 |阅读模式
  原文: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 – 2
Client Access Role – 4
Unified Messaging Role – 16
Hub Transport Role – 32
Edge 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.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143255-1-1.html 上篇帖子: 通过Exchange 的 Powershell批量创建AD账户和邮箱 下篇帖子: C#调用PowerShell管理Exchange2010
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表