从C#调用的导入模块抛出异常 [英] Import module called from C# throws exception
本文介绍了从C#调用的导入模块抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中使用点网版本4.5和SCVMM 2012 r2尝试导入模块
PowerShell powershell = PowerShell.Create();
powerShell.Commands.AddCommand( Import-Module)。AddParameter( 名称, virtualmachinemanager跨度>);
powerShell.Invoke(); // 抛出异常。
我尝试了什么:
即使尝试过以下方法,
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule( new string [] { @ C:\vm \vm.psd1});
Runspace runSpace = RunspaceFactory.CreateRunspace(iss);
runSpace.Open();
两者都不起作用。请帮助在C#中解决这个问题。在此先感谢
解决方案
也许您可以尝试 New-SCVMCheckpoint cmdlet, New-SCVMCheckpoint | Microsoft Docs [ ^ ]
Hi,
I tried import module in C# with dot net version 4.5 and SCVMM 2012 r2
PowerShell powershell = PowerShell.Create();
powerShell.Commands.AddCommand("Import-Module").AddParameter("Name", "virtualmachinemanager");
powerShell.Invoke(); // This throws exception.
What I have tried:
Even tried below method,
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new string[] { @"C:\vm\vm.psd1"});
Runspace runSpace = RunspaceFactory.CreateRunspace(iss);
runSpace.Open();
Both did not work. Please help in solving this issue in C#. Thanks in advance
解决方案
Maybe you can try the New-SCVMCheckpoint cmdlet, New-SCVMCheckpoint | Microsoft Docs[^]
这篇关于从C#调用的导入模块抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文