Powershell DSC 无法调用 Invoke-DscResource cmdlet
Powershell DSC Cannot invoke the Invoke-DscResource cmdlet
我正在尝试使用 DSC 配置我的 Service Fabric 群集虚拟机规模集中的节点。进行一些注册表编辑,以保持小我只在下面显示一个。当我 运行 自己手动操作这些功能时,它们工作正常。尝试将它们嵌套在一个函数中时出现错误。
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
启用调试后显示真正的异常
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 选项,而且 Google 似乎过滤掉了 Invoke-DscResource 的所有错误,或者我是第一个使用它的人。有谁知道解决方案?也许我不必为 WindowsDefender 模块使用 Invoke-DscResource,但我没有看到其他方法。
我用下面的博客信息弄明白了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;
}
}
我正在尝试使用 DSC 配置我的 Service Fabric 群集虚拟机规模集中的节点。进行一些注册表编辑,以保持小我只在下面显示一个。当我 运行 自己手动操作这些功能时,它们工作正常。尝试将它们嵌套在一个函数中时出现错误。
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
启用调试后显示真正的异常
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 选项,而且 Google 似乎过滤掉了 Invoke-DscResource 的所有错误,或者我是第一个使用它的人。有谁知道解决方案?也许我不必为 WindowsDefender 模块使用 Invoke-DscResource,但我没有看到其他方法。
我用下面的博客信息弄明白了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;
}
}