I have a Ps script which is called from a C#
application.
The Powershell script is being called with the format.
var scriptFile = "./run_script.ps1 " +
$"-sql_server {'"' + serverName + '"'} " +
$"-database {'"' + dbName + '"'} ";
MessageBox.Show(scriptFile);
var startInfo = new ProcessStartInfo
{
FileName = @"powershell.exe",
Arguments = scriptFile,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
var process = new Process { StartInfo = startInfo };
process.Start();
The value of servername
is being read from a configuration file. The message box comes up with the string below
./run_script.ps1 -sql_server "**Server1,5002**" -database "Test"
However from the script file
param ($sql_server,$database)
write-output "The deployment server is $sql_server"
The output from the C# application can be found below
The deployment server is Server1 5002
It's taking off, for the port number and replacing it with an empty space, thus causing the SQL connection to fail. What is surprising is that when the parameter is printed from the mo
I am lost as to what could be causing this, I have debugged the C# application and I can see that it's sending the string to the Ps file with a,