Question:
I am trying to execute following test.ps1
script
1 2 3 4 5 |
param([string]$name,[string]$password); write-Output "Hello $($name) my password is $($password)"; dir c:\ New-Item c:\HRTemp\test.txt -ItemType file |
on remote server using following command
1 2 3 4 5 |
StartPowershellScript("Invoke-Command", args => { args.Append("ScriptBlock", "{{c:\\test.ps1 -name dato -password test}}" ); }); |
I was able to successfully invoke this command from command line and now I want the same using cake script.
I am using Cake.Powershell addin.
When I try to execute it with one curly brace {c:\\test.ps1 -name dato -password test}
, I am getting error:
Error: Input string was not in a correct format.
When I try it with two curly brace
{{c:\\test.ps1 -name dato -password test}}
output is the following
Executing: Invoke-Command -ScriptBlock {{c:\test.ps1 -name dato -password test}}
but, when I check on remote server test.txt file is not created.
Do you have any ideas why this is happening?
Answer:
This is caused by the different handling of curly braces by the ProcessArgumentBuilder
used internally by the Cake.Powershell addin, and the format parser used internally in Cake’s internal logger.
I submitted a PR to Cake.Powershell which has now been merged and a new release published, so upgrading to version 0.2.7 will resolve this issue for you.
You should then be able to use something like the following:
1 2 3 4 5 |
StartPowershellScript("Invoke-Command", args => { args.Append("hostname").Append("-ScriptBlock {c:\\test.ps1 -name dato - password test}"); }); |
And while the log will include double braces, the actual command will only use single braces and should run correctly.