访问被拒绝打开与Office 365的Powershell会话

时间:2019-06-20 17:04:37

标签: powershell office365

当我使用全局管理员帐户连接到Office 365时遇到问题。每当我尝试连接到Exchange Online,Azure AD,Skype for Business和Sharepoint Online时,我都会收到一次拒绝访问错误。一旦发生此错误,并且如果我再次运行连接脚本,便可以成功连接。

我尝试了多个帐户并仔细检查了权限。

$orgName="<orgname>"
$username = "globaladmin"
$pwdTxt = Get-Content "C:\temp\ExportedPassword.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString 
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
Connect-MsolService -Credential $credObject
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -credential $credObject
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credObject
Import-PSSession $sfboSession
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credObject -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credObject -Authentication "Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc

我希望每次都能第一次成功连接。

0 个答案:

没有答案