private IDscRes DscResApplyConfig(IHasDiagnostics result, IDscRes config,
                                          out bool rebootRequired)
        {
            using var ses = CimSession.Create(config.ComputerName ?? DscRes.DefaultCimHostname);
            using var cls = ses.GetClass(DscRes.DscCimNamespace, config.TypeName);
            using var cim = new CimInstance(DscRes.LcmCimClassName, DscRes.DscCimNamespace);

            var mofBody = DscRes.BuildMof(config, cls);

            _log.LogDebug("Generated MOF:\n{0}", mofBody);
            var mofBodyBytes = DscRes.ToUint8(mofBody);
            var methodParams = new CimMethodParametersCollection
            {
                CimMethodParameter.Create("ModuleName", config.ModuleName, CimFlags.None),
                CimMethodParameter.Create("ResourceType", config.TypeName, CimFlags.None),
                CimMethodParameter.Create("resourceProperty", mofBodyBytes, CimFlags.None),
            };

            CimMethodResult methodResult;

            lock (_dscSync) {
                methodResult = ses.InvokeMethod(cim, "ResourceSet", methodParams);
            }
            rebootRequired = (bool)methodResult.OutParameters["RebootRequired"].Value;

            lock (_dscSync) {
                methodResult = ses.InvokeMethod(cim, "ResourceGet", methodParams);
            }
            var dscResConfigs = (CimInstance)methodResult.OutParameters["configurations"].Value;

            var state = config;

            state.Results = new Dictionary <string, string>();
            foreach (var p in dscResConfigs.CimInstanceProperties)
            {
                state.Results[p.Name] = p.Value?.ToString() ?? string.Empty;
            }

            lock (_dscSync) {
                methodResult = ses.InvokeMethod(cim, "ResourceTest", methodParams);
            }
            state.InDesiredState = (bool)methodResult.OutParameters["InDesiredState"].Value;

            return(state);
        }
        private bool DscResTestConfig(IHasDiagnostics result, IDscRes config)
        {
            using var ses = CimSession.Create(config.ComputerName ?? DscRes.DefaultCimHostname);
            using var cls = ses.GetClass(DscRes.DscCimNamespace, config.TypeName);
            using var cim = new CimInstance(DscRes.LcmCimClassName, DscRes.DscCimNamespace);

            var mofBody = DscRes.BuildMof(config, cls);

            _log.LogDebug("Generated MOF:\n{0}", mofBody);
            var mofBodyBytes = DscRes.ToUint8(mofBody);
            var methodParams = new CimMethodParametersCollection
            {
                CimMethodParameter.Create("ModuleName", config.ModuleName, CimFlags.None),
                CimMethodParameter.Create("ResourceType", config.TypeName, CimFlags.None),
                CimMethodParameter.Create("resourceProperty", mofBodyBytes, CimFlags.None),
            };

            CimMethodResult methodResult;

            lock (_dscSync) {
                methodResult = ses.InvokeMethod(cim, "ResourceTest", methodParams);
            }
            return((bool)methodResult.OutParameters["InDesiredState"].Value);
        }