Closed bumbeishvili closed 7 years ago
Please use "StartPowershellFile" over "StartPowershellScript" for script files.
@SharpeRAD in saying that, it's currently not possible to execute any command that uses a PowerShell ScriptBlock, since the curly braces get interpreted differently. Is it worth maybe including a setting to prevent echoing the command to the log?
No, I was getting at preventing this from executing. As it stands, including a curly brace is fine from an execution point of view, but the call to ICakeLog
(at least in the case of cake.exe
and its CakeBuildLog
implementation) fails because the curly braces are implemented differently.
In saying that, I've just tested and using a module to replace the default ICakeLog
implementation and the only way to get this to work is something along the lines of this (hacky) solution:
public void Write(Verbosity verbosity, LogLevel level, string format, params object[] args)
{
if (verbosity > Verbosity) return;
_console.WriteLine(format.Contains("ScriptBlock") ? format.Replace("{", "{{").Replace("}", "}}") : format,
args);
}
Is it worth maybe changing that line in PowerShellRunner
to double up any curly braces it finds since even string.Format
will choke on them as-is?
Good call, PR away 😄 or I'll look at it tonight.
Done! #8 🍰
@SharpeRAD How can I start powershell script file on remote server?
I've updated the readme to include a remote file example, please be aware paths are relative to the server your running the script on, not from. Also checkout the troubleshooting section.
How can I pass parameters to that script? More specifically what my needs are:
I need to execute test.ps1
file in remote server,
which is located under hr2-02.bog.ge
domain on C:\
disk
I have every permission & access issue resolved
remote powershell file content is following
param([string]$name,[string]$password);
write-Output "Hello $($name) my password is $($password)";
dir c:\
New-Item c:\HRTemp\test.txt -ItemType file
So I need to pass name
and password
parameters
@bumbeishvili as a workaround, note that your original solution (using Invoke-Command
with ScriptBlock
) should work with Cake.Powershell version 0.2.7 since my PR is included in that version.
In saying that, I would defer to @SharpeRAD on StartPowershellFile
being the "proper" way of doing it..
@agc93, @SharpeRAD it worked, thanks both :+1:
One issue left, logs are not displaying , so It's really hard to debug
update
I was able to display logs using command
StartPowershellScript(powershellStringCommand, new PowershellSettings().SetLogOutput());
I updated the ReadMe again to include arguments for "StartPowershellFile".
I am trying to execute following
test.ps1
scripton remote server using following command
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?