【发布时间】:2017-03-06 22:53:07
【问题描述】:
我使用内联脚本创建了一个PSCredential,并且能够访问该凭据,直到创建凭据的 PowerShell 会话打开。当我关闭并重新打开 PowerShell 以再次运行脚本时,我无法访问 $TFSAdminCred:
$UserID = "xyz"
$PswdFile = "\\Server1\TFSencrypt$\Pswd.txt"
$KeyFile = "\\Server1\TFSencrypt$\AES.txt"
$Key = New-Object byte[] 16
[System.Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | Out-File $KeyFile
$Key = Get-Content $KeyFile
$Pswd = "password" | ConvertTo-SecureString -AsPlainText -Force |
ConvertFrom-SecureString -Key $Key | Out-File $PswdFile
$TFSAdminCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserId, (Get-Content $PswdFile | ConvertTo-SecureString -Key $Key)
【问题讨论】:
-
变量不会在 powershell 重启后持续存在
-
任何存储它们以供重复使用的建议将不胜感激。