I need to configure ExecutionPolicy as 'RemoteSigned' at initial session state or somehow before execution of script. I don't want to execute script to set policy. This would alter the policy at client machine which i don't want.
In Powershell 5.0 reference assemblies one can do easily,
var iss = InitialSessionState.CreateDefault();
iss.ExecutionPolicy = ExecutionPolicy.RemoteSigned
but how can I achieve the same while remaining with Powershell 4.0 as referenced assemblies.
C# code to execute script
var iss = InitialSessionState.CreateDefault();
iss.ExecutionPolicy = ExecutionPolicy.RemoteSigned; --> this is OK for Powershell ReferenceAssemblies 5.0 but not 4.0
iss.ImportPSModule(new[] { typeof(Parameter).Assembly.Location });
using (var powerShell = PowerShell.Create(iss))
{
var psScript = _inlineScript ?? File.ReadAllText(_path);
powerShell.AddScript(psScript);
}