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

问题描述

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

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

请有人提供建议。

解决方法

我玩耍并找到了解决方案。似乎变量是通过会话传递的,无论它是否运行新脚本。

这部分代码对其进行了整理。

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
                    }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...