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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744660304a4586419.html
评论列表(0条)