I want to execute the PowerShell script without SDK. In my project, I have to execute the PowerShell script and also want to create an EXE file for the same. But the problem is:
When I remove Microsoft.PowerShell.SDK then the script is not executed and gives an error but creates an exe file. Error is "Cannot load PowerShell snap-in Microsoft.PowerShell.Diagnostics because of the following error: Could not load file or assembly".
When the above package is not removed from the project then the script is working fine but it gives an error while creating an exe file.
Please share your suggestion.
Here is my code:
string readLocationFile = File.ReadAllText(@"gravity_location.ps1");
using (PowerShell powerShell = PowerShell.Create())
{
powerShell.AddScript(readLocationFile);
powerShell.AddParameter("name", _locationName.Text);
powerShell.AddParameter("targetPath", filePath);
powerShell.Invoke();
}