当密码以空格开头时,连接到Office 365 Powershell失败

问题描述 投票:0回答:1

我正在尝试使用用户名和密码通过脚本连接到Powershell。当密码以passwordherebeginwithspace之类的空格开头时,身份验证失败。

会话创建行如下:**$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection -ErrorAction Stop;**

请帮助。

powershell remote-server
1个回答
0
投票

这取决于您尝试声明密码的确切程度,如果您使用的是get-credentials,则没有关系。

如果您使用的是$password = password之类的符号,则必须将其包装起来,例如

$password = " Password"

通常,如果您要连接到o365,请尝试使用以下内容。

$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

您也可以使用以下方式断开会话连接:>

Remove-PSSession $Session

© www.soinside.com 2019 - 2024. All rights reserved.