windows - 如何在 Powershell 的 GetCredential 中传递密码?
问题描述
我正在尝试执行以下脚本:
$EP = ExecutionPolicy
$Username = 'backup'
$Password = Get-Content 'C:\SecureString.txt' | ConvertTo-SecureString
$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
Import-Module VMware.DeployAutomation, ConfluencePS
if ($EP -eq 'Unrestricted') {
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
}
Set-ConfluenceInfo -BaseURI 'https://confluence.my.company' -PromptCredentials -Credential $Cred
Get-ConfluencePage
问题是即使使用用户名和密码传递变量,它仍然会提示我身份验证窗口,我没有找到任何方法来禁用或避免它。
我是否以正确的方式做事?
提前致谢。
解决方案
由于我同时使用了 -PromptCredentials 和 -Credential ,因此无论它已经有用户名和密码,都会提示窗口,因此解决方案即将删除 -PromtCredentials 命令。
Set-ConfluenceInfo -BaseURI 'https://confluence.my.company' -Credential $Cred
推荐阅读
- javascript - Flask - 由 D3 读取的临时 CSV 为空
- android - 如何为 React Native 的 64 位版本准备我的应用程序?
- vuejs2 - Vue - 将阿波罗查询结果从父组件传递给子组件
- arrays - 如何使用 MongoDB 根据数组元素对记录进行分组
- entity-framework - EntityFramework 迁移:AlterColumn DateTime 到 DateTimeOffset
- elixir - 如何从测试覆盖率分析中排除特定文件?
- unity3d - 在包管理器中找不到 Unity AR Foundation
- python - 如何允许我的应用程序的其他用户从他们的计算机访问 RDS?
- dart - Flutter:长按后激活多个手势检测器
- regex - EBNF 用于捕获两个可选值之间的逗号