On running my below code, I get error on Powershell.create as below, has anyone seen this error before, I have Micosoft.Powershell.Sdk installled. What is wrong?? also I dont have InvokeAsync method in my powershell methods? why is that
Code:
public async Task<string> RunScript( string contentScript, Dictionary<string, EntityProperty> parameters)
{
List<string> parameterList = new List<string>();
foreach( var item in parameters )
{
parameterList.Add( item.Value.ToString() );
}
using( PowerShell ps = PowerShell.Create() )
{
ps.AddScript( contentScript );
ps.AddParameters( parameters );
IAsyncResult async = ps.BeginInvoke();
StringBuilder stringBuilder = new StringBuilder();
foreach( PSObject result in ps.EndInvoke( async ) )
{
stringBuilder.AppendLine( result.ToString() );
}
return stringBuilder.ToString();
}
}
Error:
System.NullReferenceException: 'Object reference not set to an instance of an object.' 5__4 was null.