I want to execute a powershell using the .net Powershell SDK. I have this working fine. Before I execute it I want to check that the script has been signed by my code signing certificate - this is easy enough to do from within powershell itself using Get-AuthenticodeSignature but I would like to do this in code before choosing to execute this script.
Solution:
Runspace runSpace = RunspaceFactory.CreateRunspace();
runSpace.Open();
Pipeline shell = runSpace.CreatePipeline();
shell.Commands.AddScript(String.Format("Get-AuthenticodeSignature '{0}'", Filename));
Signature sig = (shell.Invoke()[0]).BaseObject as Signature;
bool isValid = sig.Status == SignatureStatus.Valid;