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



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

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

powershell -executionpolicy bypass -file install-sshed.ps1

我收到这样的错误:

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

我做错了什么?

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

powershell -executionpolicy bypass -file "c:scriptsinstall-sshed.ps1"

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

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

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

例如,从当前目录运行

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

或者从嵌套文件夹运行:

powershell -execution policy unrestricted -file ".configtest.ps1"

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

其他答案的补充。

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

它还建议您应该cd C:Program FilesOpenSSH但存档位于子文件夹中,我不得不将其解压缩到父 OpenSSH 文件夹中。

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

powershell.exe -ExecutionPolicy Bypass -File 'C:Program FilesOpenSSHuninstall-sshd.ps1'
del 'C:Program FilesOpenSSH'
Expand-Archive D:DownloadsOpenSSH-Win64.zip -DestinationPath 'C:Program FilesOpenSSH'
copy 'C:Program FilesOpenSSHOpenSSH-Win64*' 'C:Program FilesOpenSSH'
del 'C:Program FilesOpenSSHOpenSSH-Win64'
powershell.exe -ExecutionPolicy Bypass -File 'C:Program FilesOpenSSHinstall-sshd.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:Program FilesOpenSSHinstall-sshd.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:Program FilesOpenSSHFixHostFilePermissions.ps1'
powershell.exe -ExecutionPolicy Bypass -File 'C:Program FilesOpenSSHFixUserFilePermissions.ps1'
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic

最新更新