错误,而试图
早上好,我有一个问题想O负载PowerShell的模块调用MSOnline在ASP.NET 下面这个链接之后加载PowerShell的模块“MSOnline”在ASP.NET Web应用程序: 错误,而试图
这是一个Button,它通过C#中的Code Behind运行脚本。当我试图加载模块时,它引发了一个异常。
protected void Bexecute_Click(object sender, EventArgs e)
{
// Import-Module MSOnline
try
{
//Loading MSOnline using a InitialSessionState
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new string[] { "MSOnline" });
//Before the solution iss has an exception of "not found" the MSOnline Module
//Create a runspace
Runspace test = RunspaceFactory.CreateRunspace(iss);
//Open a Runspace
test.Open();
//Create a Pipeline
Pipeline pipeLine = test.CreatePipeline();
//Create the StringBuilder to get append the script
StringBuilder script = new StringBuilder();
//Take the script from Tscript (TextBoxt with ID="Tscript" in default.aspx
script.AppendLine(@"Get-Module -ListAvailable");
//Add the script and commands to the pipeline;
pipeLine.Commands.AddScript(script.ToString());
//Execute script and get the PSObject Results collection
Collection<PSObject> resultObjects = pipeLine.Invoke();
//Close the Runspace
test.Close();
if (resultObjects.Count > 0)
{
/*** DO SOMETHING WITH THE PSObjects ***/
}
}
catch (System.Management.Automation.RuntimeException ex)
{
status.AppendLine(ex.Message);
}
}
我需要的是什么可能是错的。我引用了system.management.automation(dll)。但我不知道为什么没有列出它是否安装它。感谢您的帮助。我发现MSOnline .dll文件位于:C:\ windows \ system32 \ WindowsPowerShell \ v1.0 \ Modules \ MSOnline 但是,如果我尝试从Visual Studio手动添加它说“MSOnline不存在” 。 这是很奇怪的,因为都有相同的权限到文件夹。这是怎么回事! :S本是如此令人沮丧...
为了得到ASP.NET Web应用程序在x64位架构上运行,你应该这样做:
1,MS在线服务助理需要下载并安装 微软在线服务登录助手 - 64位版本http://go.microsoft.com/fwlink/?linkid=236300
需要下载并安装 微软在线服务模块的Windows PowerShell(64位版本) http://go.microsoft.com/fwlink/?linkid=236297这一步Ÿ后
2.MS在线模块的PowerShell的您可以同时运行:Get-模块-ListAvailable和模块MSOnline将陆续上市。 但它仍然没有工作在64位的战略目标。原来的海报使用win8的64位,我使用赢得8.1 64位,它的工作原理也是如此。
-
复制从(路径1)至(路径2)的MSOnline模块文件夹,其中
(路径1) - >“C:\ Windows \ System32下\ WindowsPowerShell \ V1.0 \模块\ MSOnline”
和
(路径2) - > “C:\ WINDOWS \ Syswow64资料\ WindowsPowerShell \ V1.0 \模块\ MSOnline”
考虑我的Windows 8.1下的VS2013运行此和64位的架构。
这样做后的MSOnline模块在获取-模块-ListAvailable上市(从Web应用程序,而不仅仅是PowerShell的)),这样我就可以导入并使用它。