0

I am trying to run a powershell script through ASP.NET C# code. This is the code -

Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();

Command cmd = new Command(filePath); //filePath is the ps1 script file
parameters.ForEach(p => cmd.Parameters.Add(p.Key, p.Value));

pipeline = runspace.CreatePipeline();
pipeline.Commands.Add(cmd);

pipeline.Output.DataReady += Output_DataReady;
pipeline.Error.DataReady += Error_DataReady;
pipeline.StateChanged += Pipeline_StateChanged;

Collection<PSObject> results = pipeline.Invoke(); // This is where the exception gets thrown
runspace.Close();

I get error when I try to run a basic powershell script with any Az commands, for eg Connect-AzAccount gives me error -

Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.”

On checking, the VM where I run this contains only Az modules and no AzureRm modules.

Abhishek Anand
  • 101
  • 1
  • 8
  • "and no AzureRm modules" <-- sounds like a plausible explanation, maybe try addressing that? – Mathias R. Jessen May 07 '21 at 13:17
  • Yeah, so I added that line to clarify that I have already checked that Az and AzureRm modules are not present simultaneously on the VM. I installed Az module and have verified that there are no AzureRm modules to collide with Az. So I should be good wrt that. – Abhishek Anand May 07 '21 at 18:28

0 Answers0