我一直试图弄清楚如何在PowerShell中回答提示 . 我的用例相当基本;在我启动PowerShell会话后,我希望加载SSH密钥 .

我现在面临的问题是我手动必须为我的SSH密钥添加密码 . 我宁愿自动化 .

这就是我现在要做的事情:

Add-SshKey 

Start-Sleep -Milliseconds 5000

[System.Windows.Forms.SendKeys]::SendWait(“MyPassword01{ENTER}”)

并且在提示期间必须手动按Enter键后出现此错误:

MyPassword01 : The term 'MyPassword01' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ MyPassword01
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MyPassword01:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

另一个奇怪的行为是字符串 MyPassword01 似乎已写入错误上方的PowerShell窗口, but AFTER 提示:

Enter passphrase for /c/Users/Todai/.ssh/ps_id_rsa:
Finished!
Loading personal and system profiles took 25940ms.
~ $ MyPassword01