Importing PowerShell module in C#

后端 未结 2 1839
长情又很酷
长情又很酷 2020-12-03 15:08

I\'m trying to write some C# code to interact with Lync using PowerShell, and I need to import the Lync module before executing the Lync cmdlets. However, my code doesn\'t s

2条回答
  •  时光说笑
    2020-12-03 16:00

    Try to use the PowerShell class AddCommand method.

    ps.AddCommand("import-module Lync");
    

    Or you can use the Runspace class, you can find an example here : http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C

提交回复
热议问题