VMware Cloud Community
OON1
Contributor
Contributor

Get-ContentLibrary issues using C# System.Management.Automation

Hello,

I am invoking a powershell script using C# in .NET and the System.Management.Automation package.

It has been working with PowerCLI in my scripts for a long time, however when i add the command Get-ContentLibrary i constantly get the error An error occurred while trying to get content libraries by names. I do not get this error if I execute the same powershell-function directly from the ISE.

I have tried to find any differences between the ISE PS environment and the C# PS environment. They use the same powershell version (5.1.14393.4583), same PowerCLI version (12.4.0) etc.

 Is there something I am not aware of? I know this question is entering .NET domain, but as I have spent many hours on the issue now any help is greatly appreciated! 

Kind regards,

Oliver

0 Kudos
4 Replies
LucD
Leadership
Leadership

That looks as if OBN is not working for whatever reason in the C# environment.

Is anything returned when you do a Get-ContentLibrary without parameters?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
OON1
Contributor
Contributor

Thanks for the reply, @LucD !

Yes, If i just run $test = Get-ContentLibrary i get the same error Get-ContentLibrary An error occurred while trying to get content libraries by names. This seems really odd?

Here's the inner exception: "Could not retrieve handler field info from the HttpClient .net type."

I have attempted to completely reinstall PowerCLI and its sub-components, without any luck.

0 Kudos
LucD
Leadership
Leadership

Indeed, strange.
No clue why this would happen, but then I have no experience in calling cmdlets from C#.

You could open an SR, but I'm afraid GSS will require a Developer Support contract for this.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
OON1
Contributor
Contributor

For those encountering the same error:

Upgrading .NET from 4.6.1 to 4.8 resolved this issue.

0 Kudos