azure - 从 asp 核心网站导入带有 powershell 的模块
问题描述
我目前正在尝试从我的 asp 核心应用程序中调用一个 powershell 应用程序。
我的第一个命令是 Import-Module 以确保加载了正确的模块。
我尝试了几种方法来做到这一点:
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand("Import-Module AzureRm").Invoke();
}
这会引发 CommandNotFoundException:
术语“Import-Module AzureRm”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
如果我改用 AddScript,我根本不会得到任何反馈:
var result = ps.AddScript("Import-Module AzureRm").Invoke();
结果始终作为空对象返回。
甚至可以在 ASP 核心应用程序中使用 Import-Module 吗?
如何从 AddScript 获得结果而不是空对象?
解决方案
推荐阅读
- unity3d - 根据 Unity 中的另一个纹理更改纹理的颜色?
- python - 在python中,哪些二元运算符可以同时具有NoneType的操作数?
- php - 在这种情况下如何使用 Laravel 存储多个数据?
- bash - 如何遍历目录并仅显示文件名
- mongodb - 按多个字段分组并在两个条件下自定义总和
- list.js - 禁用 list.js 中的类似结果
- laravel - 在 Laravel 中对一个函数执行两个操作,可能吗?
- javascript - 我想重定向到一个网站,然后点击它上面的按钮
- c++ - 我可以一次检查一小部分布尔值吗?
- python - 如何将 Django request.FILES (这是一个图像)作为二进制文件读取