如何在未安装Exchange命令行管理程序的情况下调用Exchange命令在标准域计算机上获取邮箱信息?
答案 0 :(得分:0)
我编写了一个脚本来使用localy所有的Exchange 2010+命令,而无需安装交换工具。
使用
Import-ExchTools 'MyDomain'
get-mailbox $(whoami)
包含在您的脚本中
function Get-RmExchSession ($AD='MyDomain') {
Get-PSSession | Remove-PSSession
$SrvBlackList = @('vexchmb7','vexchmb6', 'vexchtopt1')
$PoolExch = $(
(Get-ADGroupMember -server $AD 'Exchange Servers') | ?{$_.objectClass -eq 'computer'} | ?{$_.Name -and $SrvBlackList -notcontains $_.name} | Sort-Object -Descending CreationDate | %{
[pscustomobject][ordered]@{
name = $_.Name
dNSHostName = "$($_.Name).$AD.adds"
}
}
)
foreach ($exch in $PoolExch) {
$ExchSession = $null
#Write-Host $Exch.dNSHostName -nonewline
if (Test-connexion $Exch.dNSHostName) {
# on se connecte au dernier Srv exchange mis en place, le plus ressant
# ne fonctionne pas sur les AD avec approbation unidirectionnele, il faut le credential ADMIN
$ExchSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$($Exch.dNSHostName)/PowerShell/" -ea SilentlyContinue
if ($ExchSession) {
#Write-Host " Session OK" -fore Green
return $ExchSession
} else {
Write-host " Impossible de se connecter avec le Current Credential, tentative avec '$AD\Administrateur'" -fore Red -NoNewline
}
}
}
$null
}
function Import-ExchTools ($AD='MyDomain') {
$exchSess = (Get-RmExchSession $AD)
if ($exchSess) {
Import-PSSession $exchSess -wa 0 | Out-Null
$exchSess
}
return $null
}