【问题标题】:The argument 'install-sshed.ps1' to the -File parameter does not exist | powershell-File 参数的参数“install-sshed.ps1”不存在|电源外壳
【发布时间】:2019-03-24 14:42:07
【问题描述】:

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

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

powershell -executionpolicy bypass -file install-sshed.ps1

我收到这样的错误:

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

我做错了什么?

【问题讨论】:

  • Powershell not 如果没有提供路径,则默认使用当前目录,以显式引用当前文件夹在文件名前加上.\ => .\install-sshed.ps1 或使用@engineerer's answer建议的绝对路径
  • @LotPings:需要显式路径仅适用于-Command,不适用于-File;如果后者引用当前目录中的文件,则后者很乐意接受仅文件名参数。

标签: powershell ssh windows-7-x64


【解决方案1】:

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

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

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

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

【讨论】:

    【解决方案2】:

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

    例如,从当前目录运行

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

    或从嵌套文件夹运行:

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

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

    【讨论】:

    • 是的,Set-Location 是个错误;我用cd 替换了它,它在cmd.exe 和PowerShell(它是Set-Location 的别名)中都可以使用。另请注意,install-sshed.ps1 相对路径 - 它隐含相对于当前目录(与 .\install-sshed.ps1 相同)。好点回复-NoProfile
    【解决方案3】:

    除了其他答案。

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

    还建议您将cd 转换为C:\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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-02
      相关资源
      最近更新 更多