windows - 通过 SSH 使用 CMD 运行 PowerShell 命令
问题描述
我在 Windows Server 2019 上使用命令提示符 (CMD)运行以下PowerShell命令,它可以正常工作:
powershell -command "Get-Childitem -Path [my source path] -Include *.bak -File -Recurse | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1 | Compress-Archive -Force -DestinationPath [my target path].zip"
但是当我想通过SSH运行它时:
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [username]@[server] powershell -command "Get-Childitem -Path [my source path] -Include *.bak -File -Recurse | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1 | Compress-Archive -Force -DestinationPath [my target path].zip"
我得到错误:
'Sort-Object' 不是内部或外部命令、可运行程序或批处理文件。
解决方案
推荐阅读
- javascript - 映射函数React中的条件表单元格
- r - 如果命令具有像“cmd | head”这样的管道,我如何使用 system 或 system2
- reactjs - 如何从异步存储中获取项目,在键中设置值,然后使用该值向 api 发出 axios 请求以进行响应?
- sql - 按顺序组合记录
- c# - 使用类库静态方法的 Serilog 输出
- google-cloud-run - Terraform中如何控制资源是否存在?
- javascript - 直接导出反应属性与 toRef 包装
- javascript - (Three.JS) 如何循环 lerp 场景背景颜色?
- database - 用户“postgresql”的密码验证失败
- amazon-web-services - 无法摆脱 s3 上的“拒绝访问”错误