-File参数的参数'install-sshed.ps1'不存在|电源外壳

问题描述 投票:0回答:2

我正在使用PowerShell向Windows 7 x64添加密钥

到目前为止,我已经使用powershell尝试了以下命令

powershell -executionpolicy bypass -file install-sshed.ps1

我得到这样的错误:

-File参数的参数'install-sshed.ps1'不存在。提供现有“.ps1”文件的路径作为-File参数的参数

我做错了什么?

powershell ssh windows-7-x64
2个回答
2
投票

您的PowerShell会话似乎是在与PowerShell脚本不同的文件夹中启动的。尝试添加PowerShell脚本的完整路径:

powershell -executionpolicy bypass -file "c:\scripts\install-sshed.ps1"

或者,首先切换到*.ps1文件所在的目录:

cd c:\scripts
powershell -executionpolicy bypass -file install-sshed.ps1

1
投票

除了上面的答案,我还想补充一点,你也可以使用相对路径。

例如,从当前目录运行

powershell -execution policy unrestricted -file ".\test.ps1"

或者从嵌套文件夹运行:

powershell -execution policy unrestricted -file ".\config\test.ps1"

我还建议添加以下参数:-noprofile这将确保不会加载任何用户配置文件,最佳做法是在运行脚本时执行此操作。你可以找到一个有趣的读here


0
投票

除了其他答案。

你可能已经下载了OpenSSH-Win32_Symbols.zipOpenSSH-Win64_Symbols.zip - 这些都不是必需的二进制文件。您可以尝试分别下载OpenSSH-Win32.zipOpenSSH-Win64.zip版本。

另外它建议你应该cdC:\Program Files\OpenSSH但是存档是在子文件夹中我必须将它提取到父OpenSSH文件夹。

额外:asterikx描述here权限的常见问题,如果某些内容无法正常工作(假设下载的存档位于D:\Downlaods),您可能会发现按照这些步骤重新安装openssh很有用:

powershell.exe -ExecutionPolicy Bypass -File 'C:\Program Files\OpenSSH\uninstall-sshd.ps1'
del 'C:\Program Files\OpenSSH\'
Expand-Archive D:\Downloads\OpenSSH-Win64.zip -DestinationPath 'C:\Program Files\OpenSSH'
copy 'C:\Program Files\OpenSSH\OpenSSH-Win64\*' 'C:\Program Files\OpenSSH\'
del 'C:\Program Files\OpenSSH\OpenSSH-Win64\'
powershell.exe -ExecutionPolicy Bypass -File 'C:\Program Files\OpenSSH\install-sshd.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:\Program Files\OpenSSH\install-sshd.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:\Program Files\OpenSSH\FixHostFilePermissions.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:\Program Files\OpenSSH\FixUserFilePermissions.ps1'
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic
© www.soinside.com 2019 - 2024. All rights reserved.