首页 > 解决方案 > 如何在 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

问题是即使使用用户名和密码传递变量,它仍然会提示我身份验证窗口,我没有找到任何方法来禁用或避免它。

我是否以正确的方式做事?

提前致谢。

标签: windowsapipowershellconfluence

解决方案


由于我同时使用了 -PromptCredentials 和 -Credential ,因此无论它已经有用户名和密码,都会提示窗口,因此解决方案即将删除 -PromtCredentials 命令。

Set-ConfluenceInfo -BaseURI 'https://confluence.my.company' -Credential $Cred

推荐阅读