admin管理员组文章数量:1391998
I'm trying to set up a GitLab pipeline. My runner connects to a windows server with ssh and runs a powershell script on the server.
I want to keep the script in my code because I need it for multiple servers. So creating the script on the server and executing it with my runner isn't my favourite option.
The ssh connection works and I can run simple powershell commands but I'm having trouble when using Where-Object.
The runner's using an alpine image in docker.
This is my code:
- sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$WEBSERVER" <<EOF
powershell.exe -Command "
Write-Host 'Backup start';
\$maxAgeDate = (Get-Date).AddDays(-2);
\$filesToCopy = Get-ChildItem \$localDirectory | Where-Object { \$_.LastWriteTime -gt \$maxAgeDate };
Write-Host \"Files to copy - \$(\$filesToCopy.Count)\";
Write-Host 'Backup end'
"
I get an error message about the command Where-Object being wrong or misspelled.
This works:
- sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$WEBSERVER" <<EOF
powershell.exe -Command "
Write-Host 'Backup start';
\$maxAgeDate = (Get-Date).AddDays(-2);
\$filesToCopy = Get-ChildItem \$localDirectory;
Write-Host \"Files to copy - \$(\$filesToCopy.Count)\";
Write-Host 'Backup end'
"
The Get-Command Where-Object; also works. Any ideas?
本文标签: How to use Powershell WhereObject in GitLab CI with SSHStack Overflow
版权声明:本文标题:How to use Powershell Where-Object in GitLab CI with SSH - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744660303a2618203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论