![](/img/trans.png)
[英]How can I read all Active Directory computers into an array in PowerShell?
[英]How can use I Exchange Commands on all domain computers?
在未安裝Exchange命令行管理程序的情況下,如何調用Exchange命令以在標准域計算機上獲取郵箱信息?
我編寫了一個腳本,以使用本地所有的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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.