问题描述
我已经成功构建了一个工作简单的程序,该程序可以显示菜单,并允许用户选择要打开的脚本,并且该脚本可以在同一窗口中运行。
我希望能够存储凭据,以便您在使用该程序时只需要输入一次即可,它将凭据传递给其他脚本。
请有人提供建议。
解决方法
我玩耍并找到了解决方案。似乎变量是通过会话传递的,无论它是否运行新脚本。
这部分代码对其进行了整理。
if ($cred -eq $null)
{
try {
Write-Host "`r`n"
$cred = Get-Credential -Credential $username
}
catch {
Write-Host -ForegroundColor Red "`r`nSomething has gone wrong with entering credentials. Please try run the script again or if issues persist please contact the system administrator.`r`n"
Return-ExitRestart
}