首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell DSC无法调用调用-DscResource

Powershell DSC无法调用调用-DscResource
EN

Stack Overflow用户
提问于 2018-10-09 08:31:03
回答 1查看 1K关注 0票数 0

我正在尝试使用DSC来配置服务fabric集群虚拟机规模集中的节点。做一些注册表编辑,为了保持它的小,我只显示在下面一个。当我手动运行这些函数时,它们可以正常工作。当试图将它们嵌套在一个函数中时,我会得到一个错误。

代码语言:javascript
复制
 configuration ServiceFabricNode {
     Node localhost
     {  
         SSLPerfectForwardSecrecyTLS12 ConfigureSSL {}          
         ServiceFabricAntivirusExclusions AntiVirusExclusions {}    
     }
 }

 configuration SSLPerfectForwardSecrecyTLS12 {
     Import-DscResource –ModuleName PSDesiredStateConfiguration
     Import-DscResource -ModuleName GraniResource

     # Disable Multi-Protocol Unified Hello
     Registry "DisableServerMultiProtocolUnifiedHello"
     {
         Key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol
         Unified Hello\Server"
         ValueName = "Enabled"
         ValueType = "Dword"
         ValueData = "0"
         Ensure = "Present"
         Force = $true
      } 
  }

 configuration ServiceFabricAntivirusExclusions {   
      Import-DscResource -ModuleName WindowsDefender

      [string[]]$exclusionPath = "C:\Program Files\Microsoft Service abric\","D:\SvcFab\";
      Invoke-DscResource -Name WindowsDefender -ModuleName WindowsDefender -Method Set -Property @{ IsSingleInstance = 'Yes'; ExclusionPath = $exclusionPath }

      [string[]]$exlusionProcess = "Fabric.exe","FabricHost.exe","FabricInstallerService.exe","FabricSetup.exe","FabricDeployer.exe","ImageBuilder.exe","FabricGateway.exe","FabricDCA.exe","FabricFAS.exe","FabricUOS.exe","FabricRM.exe","FileStoreService.exe";
      Invoke-DscResource -Name WindowsDefender -ModuleName WindowsDefender -Method Set -Property @{ IsSingleInstance = 'Yes'; ExclusionProcess = $exlusionProcess } 
 }

 ServiceFabricNode

结果成

代码语言:javascript
复制
Compilation errors occurred while processing configuration 'ServiceFabricNode'. Please review the errors reported in error stream and modify your configuration code 
appropriately.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5
+     throw $ErrorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ServiceFabricNode:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

启用调试后,它显示了真正的异常。

代码语言:javascript
复制
Cannot invoke the Invoke-DscResource cmdlet. The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked. Use -Force option if 
that is available to cancel the current operation.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

我找不到一个-Force选项,谷歌似乎过滤掉了调用-DscResource的所有错误,或者我是第一个使用它的。有人知道解决办法吗?也许我不必为WindowsDefender模块使用Invoke-DscResource,但我看不到其他方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-09 08:59:58

我在下面的博客信息http://nanalakshmanan.com/blog/Composite-Resources-Explained/中找到了答案

WindowsDefender是一个复合资源

代码语言:javascript
复制
configuration ServiceFabricAntivirusExclusions
{
    Import-DscResource -ModuleName WindowsDefender

    [string[]]$exclusionPath = "C:\Program Files\Microsoft Service Fabric\","D:\SvcFab\";
    [string[]]$exlusionProcess = "Fabric.exe","FabricHost.exe","FabricInstallerService.exe","FabricSetup.exe","FabricDeployer.exe","ImageBuilder.exe","FabricGateway.exe","FabricDCA.exe","FabricFAS.exe","FabricUOS.exe","FabricRM.exe","FileStoreService.exe";

    WindowsDefender x
    { 
        IsSingleInstance = 'Yes';
        ExclusionPath = $exclusionPath;
        ExclusionProcess = $exlusionProcess;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52716586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档