简体   繁体   中英

How can use I Exchange Commands on all domain computers?

How can call Exchange commands to get mailbox information on a standard domain computer without the Exchange Management Shell installed?

  • Run PowerShell directly on remote Exchange server over RDP.
  • Invoke-command on a local machine to remote Exchange Server.
  • Import-Commands of the Exchange server on a local machine.

I write a script to use localy all exchange 2010+ commands without needed instaling the exchange tools.

use like

Import-ExchTools 'MyDomain'
get-mailbox $(whoami)

include in your script

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM