我一直在试图弄清楚如何在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窗口,但是AFTER 提示符:
Enter passphrase for /c/Users/Todai/.ssh/ps_id_rsa: Finished! Loading personal and system profiles took 25940ms. ~ $ MyPassword01