简体   繁体   English

当我在本地主机上创建 RunSpace 而不提供 runspaceconnectioninfo 时,某些 PowerShell 模块(集群 cmdlet)不会被加载

[英]Some of the PowerShell module (Cluster cmdlets) does not get loaded when I create RunSpace on a localhost without providing runspaceconnectioninfo

Please refer the sample below: RunspaceSample(string.Empty);请参考以下示例: RunspaceSample(string.Empty); fails with The term 'Add-VMToCluster' is not recognized as the name of a cmdlet.失败并显示术语“Add-VMToCluster”未被识别为 cmdlet 的名称。 Whereas the RunspaceSample("localhost") or RunspaceSample("somecomputerName") succeed.而 RunspaceSample("localhost") 或 RunspaceSample("somecomputerName") 成功。 Any pointer why is it ?任何指针为什么是它? Does including RunspaceConnectionInfo changes the powershell version used or RunspaceConfiguration used for execution ?包含 RunspaceConnectionInfo 是否会更改用于执行的 powershell 版本或 RunspaceConfiguration ? Also what would be the performance impact if I create Runspace with RunSpaceConnectionInfo with ComputerName = "localhost" even for executing powershell script on a local computer ?.另外,如果我使用 RunSpaceConnectionInfo 和 ComputerName = "localhost" 创建 Runspace,即使在本地计算机上执行 powershell 脚本也会对性能产生什么影响?

Thanks谢谢

public static void RunspaceSample(string computerName)
    {
        Runspace rs;
        if (string.IsNullOrEmpty(computerName))
        {
            rs = RunspaceFactory.CreateRunspace();
        }
        else
        {
            var connectionInfo = new WSManConnectionInfo
            {
                OperationTimeout = 10000,
                OpenTimeout = 10000,
                ComputerName = computerName
            };
            rs = RunspaceFactory.CreateRunspace(connectionInfo);
        }

        rs.Open();
        PowerShell ps = PowerShell.Create();
        ps.Runspace = rs;
        string script = @"$ComputerName = 'somevm'; $null = Add-VMToCluster -Name $ComputerName -VMName $ComputerName -ErrorAction SilentlyContinue -verbose";
        ps.AddScript(script);


        Console.WriteLine("Script: {0}", script);
        Console.WriteLine("------------------------");
        foreach (PSObject result in ps.Invoke())
        {
            Console.WriteLine(result.ToString());
        }

        if (ps.HadErrors)
        {
            var sb = new StringBuilder();
            foreach (var errorRecord in ps.Streams.Error)
            {
                sb.AppendFormat("\nError: {0} CategoryInfo: {1}", errorRecord.Exception.Message, (errorRecord.CategoryInfo != null) ? errorRecord.CategoryInfo.ToString() : string.Empty);
            }

            var errorMessage = sb.ToString();
            Console.WriteLine(errorMessage);
        }
    }

The FailoverClusters module is only available in 64-bit PowerShell sessions. FailoverClusters 模块仅在 64 位 PowerShell 会话中可用。 Making this assembly as 64 bit assembly resolved the module not found issue.将此程序集设为 64 位程序集解决了未找到模块的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM