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.