微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

转换为字符串Powershell问题

如何解决转换为字符串Powershell问题

我想使用这样的信誉在线连接到Exchange:

$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

但是在尝试将“如下转换为字符串”时遇到问题

enter image description here

我仅使用.txt文件

enter image description here

解决方法

只需添加-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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。