Problem using System.Management.Automation and cmdlet "Get-printconfiguration". Need urgent help ! RRS feed

  • Question

  • I am having problem using System.Management.Automation in C# and cmdlet "Get-printconfiguration".

    Other cmdlets like Get-Printer and Get-PrinterProperty is working fine in C#.

    From the PowerShell Console, Get-PrintConfiguration is working fine, but I cant get it to work inside C# using System.Management.Automation.

    The invoke command fails with "An error occurred while performing the specified operation. See the error details for more information." But the error details is empty (null).

    I have tried both Visual Studio 2010 and 2013 on Windows 2012 R2, same problem.

    I have added reference: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0_31bf3856ad364e35\System.Management.Automation.dll

    Code snip:


    using  (PowerShell PowerShellInstance = PowerShell.Create())


       PowerShell ps = PowerShell.Create();


       foreach (PSObject Obj in ps.Invoke())          <-------- FAILS






    Any help would be helpful.

    • Moved by Fred Bao Tuesday, December 9, 2014 3:23 AM Move From .NET Framework Class Library Forum
    Monday, December 8, 2014 9:49 AM


All replies