type-conversion - 转换为字符串 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
但是我在尝试转换为字符串时遇到了一个问题,如下所示
我只使用了 .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
推荐阅读
- vue.js - 除非我清除 .cache 文件夹,否则首次构建后 Vue CLI 子编译失败
- javascript - 使用 Javascript / lodash 重新排列对象的位置
- ruby-on-rails - 搜索具有日期范围的对象
- javascript - 如何使用 Javascript 和 PHP 格式化日期时间戳
- android - 如何使用没有黑色背景的透明 Webm
- spring-boot - @DataJpaTest 忽略 `spring.datasource.url` 配置。怎么修?
- pipelinedb - PipelineDBarrival_timestamp 字段不出现
- javascript - 如何将特定 URL 重定向到另一个 URL
- xml - 如何在 scala 中加载 YAML 配置文件以将其转换为 CSV 以及具有原始数据的 XML 文件
- java - 剂量禁用 logger.debug 会影响性能吗?