C# 尝试加载Powershell模块时出错;MSOnline“;在ASP.NET web应用程序中
早上好,我在尝试在ASP.NET中加载名为MSOnline的Powershell模块时遇到一个问题 点击以下链接: 这是一个通过C#中的代码隐藏来运行脚本的按钮。当我试图加载模块时,它抛出了一个异常C# 尝试加载Powershell模块时出错;MSOnline“;在ASP.NET web应用程序中,c#,asp.net,powershell,module,office365-apps,C#,Asp.net,Powershell,Module,Office365 Apps,早上好,我在尝试在ASP.NET中加载名为MSOnline的Powershell模块时遇到一个问题 点击以下链接: 这是一个通过C#中的代码隐藏来运行脚本的按钮。当我试图加载模块时,它抛出了一个异常 protected void Bexecute_Click(object sender, EventArgs e) { // Import-Module MSOnline try { //L
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);
}
}
protectedvoidbexecute\u单击(对象发送方,事件参数e)
{
//导入模块MSOnline
尝试
{
//使用InitialSessionState加载MSOnline
InitialSessionState iss=InitialSessionState.CreateDefault();
iss.ImportPSModule(新字符串[]{“MSOnline”});
//在解决方案iss出现MSOnline模块“未找到”的异常之前
//创建一个运行空间
运行空间测试=RunspaceFactory.CreateRunspace(iss);
//打开运行空间
test.Open();
//创建管道
管道管道=test.CreatePipeline();
//创建StringBuilder以获取附加脚本
StringBuilder脚本=新建StringBuilder();
//从default.aspx中的Tscript(TextBoxt,ID=“Tscript”)获取脚本
AppendLine(@“Get Module-ListAvailable”);
//将脚本和命令添加到管道中;
pipeLine.Commands.AddScript(script.ToString());
//执行脚本并获取PSObject结果集合
集合resultObjects=pipeLine.Invoke();
//关闭运行空间
test.Close();
如果(resultObjects.Count>0)
{
/***对PSObject执行一些操作***/
}
}
捕获(System.Management.Automation.RuntimeException ex)
{
状态。附录行(例如消息);
}
}
我需要的是什么可能是错误的。我引用了system.management.automation(dll)。但是我不知道如果安装了它,为什么没有列出。谢谢你的帮助
我在C:\windows\system32\WindowsPowerShell\v1.0\Modules\MSOnline中找到了MSOnline.dll文件
但如果我试图从VisualStudio手动添加,它会说“MSOnline不存在”。
这很奇怪,因为所有人对文件夹都有相同的权限。发生了什么事!:s这太令人沮丧了…要让ASP.NET web app在x64位体系结构下运行,您应该执行以下操作: 1、需要下载并安装MS Online Services Assistant Microsoft Online Services登录助手–64位版本 需要下载并安装PowerShell的2.MS联机模块 适用于Windows PowerShell的Microsoft联机服务模块(64位版本) 在此步骤之后,您可以运行:get module-ListAvailable,模块MSOnline将被列出。 但它仍然不能在64位SOs上工作。最初的海报使用win8 64位,我使用win8.1 64位,它也能工作
完成此操作后,MSOnline模块将列在Get Module-ListAvailable(从webapp,而不仅仅是powershell)中,因此我可以导入并使用它。要使ASP.NET web app在x64位体系结构下运行,您应该执行以下操作: 1、需要下载并安装MS Online Services Assistant Microsoft Online Services登录助手–64位版本 需要下载并安装PowerShell的2.MS联机模块 适用于Windows PowerShell的Microsoft联机服务模块(64位版本) 在此步骤之后,您可以运行:get module-ListAvailable,模块MSOnline将被列出。 但它仍然不能用于64位SOs。原始海报使用win8 64位,我使用win8.1 64位,它也可以工作
完成此操作后,MSOnline模块将列在Get Module-ListAvailable(从webapp,而不仅仅是powershell)中,因此我可以导入并使用它。要使ASP.NET web app在x64位体系结构下运行,您应该执行以下操作: 1、需要下载并安装MS Online Services Assistant Microsoft Online Services登录助手–64位版本 需要下载并安装PowerShell的2.MS联机模块 适用于Windows PowerShell的Microsoft联机服务模块(64位版本) 在此步骤之后,您可以运行:get module-ListAvailable,模块MSOnline将被列出。 但它仍然不能用于64位SOs。原始海报使用win8 64位,我使用win8.1 64位,它也可以工作
完成此操作后,MSOnline模块将列在Get Module-ListAvailable(从webapp,而不仅仅是powershell)中,因此我可以导入并使用它。要使ASP.NET web app在x64位体系结构下运行,您应该执行以下操作: 1、需要下载并安装MS Online Services Assistant Microsoft Online Services登录助手–64位版本 需要下载并安装PowerShell的2.MS联机模块 微软