c# - 在跨域的 IIS 上的 C# 应用程序中运行 Powershell cmdlet
问题描述
我们必须域:NT1 和 NT2。
我们有一个 C# 应用程序,它在 Exchange 服务器(域 NT2)上调用 Powershell cmdlet。它使用NT2\User的凭据。
摘录:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
...
var connectionInfo = nw WSManConnectionInfo(
exchangeUri,
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
new PSCredential(nt2User, password));
connectionInfo.SkipRevocationCheck = true;
connectionInfo.SkipCACheck = true;
connectionInfo.SkipCNCheck = true;
using var runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
using var pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Set-User -Identity Contoso\Jill -DisplayName Jill");
pipeline.Invoke();
当我简单地在我的计算机(域 NT1)上运行这个应用程序时,一切都很好。
当应用程序部署在域 NT1 中的服务器上并托管在 IIS 上时,它会停止工作。IIS 应用程序池配置有域 NT1 ( NT1\User ) 的标识。
它在 System.Managemnt.Automation.RemoteRunspace.Open() 处引发 System.Managemnt.Automation.Remoting.PSRemotingTransportException:
Connecting to remote server mail.test.brightfulsolutions.com failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
似乎 IIS 应用程序池身份用户 NT1\User 和 Powershell 预期用户 NT2\User 冲突,但不知道该怎么做。
欢迎任何建议(代码、服务器配置)。
解决方案
推荐阅读
- python - 如何从 azure 云函数 cosmos db 查询中获得一致的结果?
- android - 如何获取 Adsense for video (AFV) 的标签 url
- macos - 无法在 VirtualBox 中访问 brew 安装的 Jenkins
- sql - 如何从字符串 SQL Server 中选择第 n 个和第 (n+1) 个单词
- amazon-web-services - AWS ASM 描述秘密详细信息和日期解析
- php - 传递给 DoctrineDataCollector::__construct() 的参数 1 必须是 Doctrine\Common\Persistence\ManagerRegistry 的一个实例
- java - 为什么我的 SensorEventListener 实现不起作用?未收到 onSensorChanged 回调
- reactjs - 从 redux-saga reactJS 中的 api 获取数据
- sql - 将一列拆分为多列(数量和名称未知)
- java - 通过提供者将 POJO 序列化为 JSON