gpt4 book ai didi

c# - New-PSSession 和 Runspacepool 说明

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:44 25 4
gpt4 key购买 nike

我需要使用 C# 中的 powershell 类运行 Exchange 在线 cmdlet。

要运行 exchange online cmdlet,我需要建立一个远程 powershell session 。

我的疑惑是:1) 如果 runspacepool 大小为 2,我应该在该 runspacepool 的两个运行空间中创建该远程 powershell session 吗?如果是,我如何/是否有办法循环运行空间以运行新的-两个运行空间中的 PSSession 命令。

2) 如果 session 在一个运行空间中过期,是否有办法从运行空间池中获取该特定运行空间,并单独在该运行空间中创建新 session ?

最佳答案

您不需要为池中的每个运行空间手动创建远程 session 。相反,在使用以下重载实例化运行空间池时提供连接信息:RunspaceFactory.CreateRunspacePool(Int32, Int32, RunspaceConnectionInfo) (如 this answer 所示):

string shell = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
var target = new Uri("http://myserver/wsman");
var secured = new SecureString();
foreach (char letter in "mypassword")
{
secured.AppendChar(letter);
}
secured.MakeReadOnly();

var credential = new PSCredential("username", secured);
var connectionInfo = new WSManConnectionInfo(target, shell, credential);

Runspace remotePool = RunspaceFactory.CreateRunspacePool(0,2,connectionInfo);

关于c# - New-PSSession 和 Runspacepool 说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31935183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com