Type conversion 转换为字符串Powershell问题

Type conversion 转换为字符串Powershell问题,type-conversion,powershell-5.0,Type Conversion,Powershell 5.0,我想使用我的cred连接到Exchange online,如下所示: $Username = "bigdaddy@love.onmicrosoft.com" $PasswordPath = "C:\PowerShell\password.txt" #Read the password from the file and convert to SecureString $SecurePassword = Get-Content $PasswordPath

我想使用我的cred连接到Exchange online,如下所示:

$Username = "bigdaddy@love.onmicrosoft.com"
$PasswordPath = "C:\PowerShell\password.txt"

#Read the password from the file and convert to SecureString
$SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
但我在尝试转换为字符串时遇到了一个问题,如下所示

我只使用了.txt文件


只需添加
-AsPlainText-Force

$Username = "bigdaddy@love.onmicrosoft.com"
$PasswordPath = "C:\PowerShell\password.txt"

#Read the password from the file and convert to SecureString
$SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword

只需添加
-AsPlainText-Force

$Username = "bigdaddy@love.onmicrosoft.com"
$PasswordPath = "C:\PowerShell\password.txt"

#Read the password from the file and convert to SecureString
$SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword

Add-Asplaintext-ForceAdd-Asplaintext-Force