如何通过使用Powershell进行CSP登录来管理交换

时间:2019-03-13 13:51:09

标签: powershell office365 azure-powershell

我试图弄清楚如何对我公司的所有租户运行powershell命令。我需要能够添加传输规则,编辑垃圾邮件过滤器设置等,而不必使用每个客户端的全局管理员帐户登录Powershell。

运行以下命令时,我无法访问,但是我可以通过Web界面设置这些内容。

#Get username and password for 0365 connection
$cred = get-credential
#Import microsoft online
Import-module msonline

#log in
connect-msolservice -credential $cred

#Connect to exchange online
$EolSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication "Basic" -AllowRedirection

Import-PSSession $EolSession -DisableNameChecking

Write-host "You are now connected to Exchange" -ForegroundColor DarkGreen

$ScriptBlock = {new-transportrule -name "Block domain.com" -senderdomainis "domain.com" -deletemessage $true}

$customers = Get-MsolPartnerContract -All
Write-Host "Found $($customers.Count) customers for this Partner."

foreach ($customer in $customers) {

$InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where-Object {$_.IsInitial -eq $true}
    Write-Host "Blocking domain.com for $($Customer.Name)"
    $DelegatedOrgURL = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name
    Invoke-Command -ConnectionUri $DelegatedOrgURL -Credential $Cred -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection -ScriptBlock $ScriptBlock -HideComputerName
}

我注意到可以将来宾用户添加到我的客户中,我是否只需将CSP帐户作为来宾用户添加到所有客户中,并为其授予全局管理员权限?即使我应该拥有CSP的全局管理员权限?

0 个答案:

没有答案
相关问题