Find Exchange Servers in the Local Active Directory Site using PowerShell
来源:互联网 发布:专业的vb振动电机 编辑:程序博客网 时间:2024/05/01 19:39
原文: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 themsExchCurrentServerRoles attribute. The server roles can be determined by comparing the value to the table listed inthis technet article. The role values are defined as follows:
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.
- Find Exchange Servers in the Local Active Directory Site using PowerShell
- Using exchange server to send email in Powershell
- Powershell 管理Active Directory常用命令
- Using the Active Directory from Java (Spring LDAP)
- Could not find server '***' in sys.servers,Execute sp_addlinkedserver to add the server to sysy.servers
- Powershell管理Active Directory 复制和拓扑
- PowerShell 批量导入/导出Active Directory
- 为 Exchange 2013 准备 Active Directory
- Using the ASP.NET 2.0 ReportViewer in Local Mode
- 转载:Using PowerShell in the build process 使用Powershell进行build
- How to authenticate against the Active Directory by using Forms authentication and Visual C# .NET
- Using Forms Authentication with Active Directory
- Query Active Directory Users using C#
- PowerShell: Using the Interactive Shell
- 更新Active Directory/Exchange Address Book的小工具
- Active Directory和Exchange灾难恢复参考文档
- Active Directory和Exchange灾难恢复参考文档
- Active Directory和Exchange灾难恢复参考文档
- printk调用过程
- Windows下使用MinGW+msys编译FFmpeg错误
- CGFloat,CGPoint,CGSize,CGRect
- P124 第46题 Fibonacci
- TestNG监听器实现用例运行失败自动截图、重运行功能
- Find Exchange Servers in the Local Active Directory Site using PowerShell
- android官网没法访问issue
- QT4 编译错误 error: collect2: ld returned 1 exit status
- 软件工程到底学什么
- 循环链表和约瑟夫环
- 如何在Kafka上对一个Topic增加replicas
- 解析版本号的字符串
- SQL级联删除
- -bash: ./startup.sh: Permission denied 解决