I have ps1 script that contains Invoke-Sqlcmd command to execute some sql queries. I am executing this ps1 file from the c# form application with the below code:
var ps1File = @executeChangeScriptPs1FilePath;
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoExit -ExecutionPolicy ByPass -File \"{ps1File}\" \"{args0}\" \"{args1}\" \"{args2}\" \"{args3}\" \"{args4}\"",
UseShellExecute = false,
Verb = "runas"
};
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
process.Close();
But its giving below error on the ps1 window;
Invoke-Sqlcmd : Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
When I execute Invoke-SqlCmd command from powershell directly its working. But when I execute from C# application giving mentioned error.
Does anyone know how to solve the problem?
Here ss for powershell screens. Left one opened from c# application. Right one opened driectly.