office 365使用服务主体或OAuth2登录powershell

时间:2016-12-12 09:22:57

标签: powershell office365

我可以找到有关如何使用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
  •   
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~      
        
    • CategoryInfo:OperationStopped:(:) [Connect-MsolService],MicrosoftOnlineException
    •   
    • FullyQualifiedErrorId:0x80048862,Microsoft.Online.Administration.Automation.ConnectMsolService
    •   
  •   

0 个答案:

没有答案
相关问题