问题描述
我正在尝试通过使用Connect-MsolService -Credential或Connect-AzureAD -Credential语句通过PowerShell连接到Azure.以下两个语句均给出错误:
I am trying to connect to Azure by PowerShell by either using the Connect-MsolService -Credential or Connect-AzureAD -Credential statement. Both statements below give an error:
$ credential =获取凭据
Connect-MsolService-凭据$ credential
Connect-MsolService:发送请求时发生错误.
在第2行:char:1
+ Connect-MsolService-凭据$ credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :OperationStopped:(:) [Connect-MsolService],HttpRequestException
+ FullyQualifiedErrorId:System.Net.Http.HttpRequestException,Microsoft.Online.Administration.Automation.ConnectMsolService
Connect-MsolService : An error occurred while sending the request.
At line:2 char:1
+ Connect-MsolService -Credential $credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], HttpRequestException
+ FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.Online.Administration.Automation.ConnectMsolService
$ credential =获取凭据
Connect-AzureAD -Credential $ credential
Connect-AzureAD:发生一个或多个错误.:发送请求时发生错误.
在第2行:char:1
+ Connect-AzureAD -Credential $ credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :AuthenticationError:(:) [Connect-AzureAD],AadAuthenticationFailedException
+ FullyQualifiedErrorId:Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD : One or more errors occurred.: An error occurred while sending the request.
At line:2 char:1
+ Connect-AzureAD -Credential $credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
当我不使用-Credential部分时,一切正常,当我不使用-Credential部分时,Windows将显示不同的登录框(办公室365网页).
Everything works fine when I leave out the -Credential part, Windows is presenting a different login box (office 365 webpage) when I leave out the -Credential part.
我该如何解决?我需要能够通过PSCredentials对象传递凭据,以便可以构建无人值守的维护脚本.
How can I solve this? I need to be able to pass the credential by the PSCredentials object so I can build an unattended maintenance script.
推荐答案
该命令对我来说没有任何问题.我总是使用此脚本块来传递凭据,这对我来说是成功的秘诀.
The command is working for me without any issues. I always use this block of script to pass credentials and it does the trick for me.
这篇关于带有PSCredential问题的Connect-MsolService -Credential和Connect-AzureAD -Credential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!