我可以找到有关如何使用Powershell为Office365创建服务主体的信息 - 但我找不到如何在Powershell中使用它们登录 . 这不可能吗?我目前正在使用此代码,该代码适用于我的管理员帐户,但不适用于服务凭据(适用于Azure):

$AdminName = "application-id" 
$Pass = ConvertTo-SecureString "application-key" -AsPlainText –Force

$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Pass 

# Azure Login working
#$tenantId = "tenant-id"
#Add-AzureRmAccount -Credential $Cred -ServicePrincipal -TenantId $tenantId


# MSOnline / Office365-Login not working
Import-Module MSOnline
Connect-MsolService -Credential $Cred

我在“Connect-MsolService”中得到的错误是:

Connect-MsolService:无法验证您的凭据 . 确保您的用户名格式为:<username> @ <domain> . 如果此问题仍然存在,请与支持部门联系Connect-MsolService -Credential $ Cred ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分类信息:OperationStopped :(: )[Connect-MsolService],MicrosoftOnlineException FullyQualifiedErrorId:0x80048862,Microsoft.Online.Administration.Automation.ConnectMsolService