Powershell DSC无法调用Invoke-DscResource cmdlet

时间:2018-10-09 08:31:04

标签: powershell azure-service-fabric dsc

我正在尝试使用DSC在我的服务结构集群虚拟机规模集中配置节点。为了使注册表保持较小,我做了一些注册表编辑,仅在下面显示。当我自己手动运行功能时,它们可以正常工作。当尝试将它们嵌套在一个函数中时,出现错误。

-P

结果进入

 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

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

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

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

1 个答案:

答案 0 :(得分:0)

我通过以下博客信息http://nanalakshmanan.com/blog/Composite-Resources-Explained/

得出了答案

WindowsDefender是复合资源

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;
    }
}