无法使用 PowerShell 连接到 Office 365

hde*_*dev 4 powershell azure microsoft-office-365

我想通过powershell连接Office 365,参考教程一个很简单的任务。但显然不适合我。

我想我错过了一个简单但重要的琐事。

一些信息:

  • 许可证是 Office 365 Business Essential
  • Azure AD 正在运行
  • 我可以在其他服务器上使用 powershell 远程处理 (WinRM)
  • 我使用管理员帐户
  • 我使用我的域并尝试了 onmicrosoft.com 域
  • 配置了双因素身份验证(附加安全验证)

我尝试了以下

PS C:\>Import-Module MSOnline
PS C:\>$msolcred = get-credential
PS C:\>connect-msolservice -credential $msolcred
connect-msolservice : The user name or password is incorrect. Verify your user name, and then type your password again.
Run Code Online (Sandbox Code Playgroud)

PS C:\> $O365Session = New-PSSession -ConfigurationName Microsoft.Exchange 
    -ConnectionUri https://ps.outlook.com/powershell 
    -Credential $msolcred -Authentication Basic 
    -AllowRedirection
New-PSSession : [ps.outlook.com] Connecting to remote server ps.outlook.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
Run Code Online (Sandbox Code Playgroud)

我使用了不同的连接 uri

PS C:\> $Session = New-PSSession -ConfigurationName Microsoft.Exchange 
    -ConnectionUri https://outlook.office365.com/powershell-liveid/ 
    -Credential $msolcred2 -Authentication Basic 
    -AllowRedirection
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message :
[ClientAccessServer=VI1PR05CA0019,BackEndServer=,RequestId=5d73dec9-b3ee-4e71-9ddd-bdaac8f79998,TimeStamp=3/7/2015 8:17:50 AM] [FailureCategory=LiveID-InvalidCreds] Access Denied For more information, see the
Run Code Online (Sandbox Code Playgroud)

非常感谢帮助!

小智 8

PowerShell 似乎不支持 O365 的双因素身份验证。

http://community.office365.com/en-us/f/148/t/222763.aspx

“如果管理员帐户启用了多重身份验证,当他使用此管理员帐户连接到 PowerShell 时,PowerShell 将无法工作。确保您创建一个具有强密码的服务帐户来运行 PowerShell 脚本,并且不要为多重身份启用该帐户验证。”

  • 可以确认是这种情况。我曾经经常使用 Powershell 进行连接,但是当我“升级”到 2FA 时却无法连接 (2认同)