Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将存储的凭证变量传递给新脚本_Powershell_Variables_Credentials_Pass Through - Fatal编程技术网

Powershell 将存储的凭证变量传递给新脚本

Powershell 将存储的凭证变量传递给新脚本,powershell,variables,credentials,pass-through,Powershell,Variables,Credentials,Pass Through,我已经成功地构建了一个简单的程序,它显示一个菜单,允许用户选择要打开的脚本,并在同一窗口中运行 我希望能够存储凭据,以便您在使用此程序时只需输入一次凭据,并将其传递给其他脚本 请有人给我提建议。我到处玩,找到了解决办法。无论会话是否运行新脚本,变量似乎都会在会话中传递 这段代码把它整理好了 if ($cred -eq $null) { try { Write-Host "`r`n"

我已经成功地构建了一个简单的程序,它显示一个菜单,允许用户选择要打开的脚本,并在同一窗口中运行


我希望能够存储凭据,以便您在使用此程序时只需输入一次凭据,并将其传递给其他脚本


请有人给我提建议。

我到处玩,找到了解决办法。无论会话是否运行新脚本,变量似乎都会在会话中传递

这段代码把它整理好了

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
                    }

“我希望能够存储凭据”-存储多长时间?只是当前
powershell.exe
进程的生存期?