我正在使用PowerShell希望的状态configuration在服务器机器上testing/设置Windowsfunction。 我所拥有的是78个WindowsFeature资源,如果需要检查和安装。 我观察到的是当LCM(本地configurationpipe理器)正在执行并检查configuration时CPU占用率过高。 我调查了一下,发现WMI提供程序“deploymentprovider”是ServerManager.DeploymentProvider.dll的一部分,负责WindowsFeature资源是它的原因。 所以问题是,有没有人遇到这个问题,并以某种方式解决?
提前致谢。
WindowsFeature资源非常多。 您可以尝试通过使用Script资源并自己编写代码(或创build自定义资源)来合并检查。 大部分CPU花费的时间可能是开销,所以如果你一次检查所有的78,它应该快得多。
Configuration cWindowsFeatures { param ( [parameter(Mandatory=$true)] $WindowsFeatures ) Import-DscResource -ModuleName PSDesiredStateConfiguration $i=0 foreach($WindowsFeature in $WindowsFeatures.keys) { $ResourceName="WindowsFeature$($i)" WindowsFeature "$ResourceName" { Name = "$WindowsFeature" Ensure = $WindowsFeatures["$WindowsFeature"][0] IncludeAllSubFeature = $WindowsFeatures["$WindowsFeature"][1] } $i++ } } function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Id, [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string[]] $WindowsFeature ) $retValue=@{} $InstalledFeatures=(Get-WindowsFeature -Name $WindowsFeature | Where-Object {$_.InstallState -eq "Installed"}).Name $retValue.WindowsFeature=$InstalledFeatures return $retValue } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Id, [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string[]] $WindowsFeature ) Install-WindowsFeature -Name $WindowsFeature } # The Test-TargetResource cmdlet is used to validate if the role or feature is in a state as expected in the instance document. function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Id, [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string[]] $WindowsFeature ) $return=$false $InstalledFeatures=(Get-TargetResource -Id $Id -WindowsFeature $WindowsFeature).WindowsFeature if($InstalledFeatures.Count -eq $WindowsFeature.Count) { Write-Verbose -Message "Seems like all features are already installed" $return=$true } else { Write-Verbose -Message "Some features are still missing. It'll be necessary to installed them." } return $return } Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource Configuration app0 { param ( [parameter(Mandatory=$true)] [string]$MachineName ) Import-DscResource -ModuleNAme cCompositeConfigurationResources Import-DscResource -ModuleName cPSDesiredStateConfiguration Node $AllNodes.Where{$_.Nodename -eq "$MachineName"}.Nodename { #region WindowsFeatures cWindowsFeatures cWindowsFeatures0 { WindowsFeatures=$Node.WindowsFeatures } #endregion WindowsFeatures } } Configuration app1 { param ( [parameter(Mandatory=$true)] [string]$MachineName ) Import-DscResource -ModuleName cPSDesiredStateConfiguration Node $AllNodes.Where{$_.Nodename -eq "$MachineName"}.Nodename { #region WindowsFeatures cWindowsFeature cWindowsFeature0 { ID = "cWindowsFeature0" WindowsFeature=$Node.WindowsFeatures.Keys } #endregion WindowsFeatures } } app0 -ConfigurationData $ConfigurationData -OutputPath C:\DSC0 -MachineName app1 app1 -ConfigurationData $ConfigurationData -OutputPath C:\DSC1 -MachineName app1 Start-DSCConfiguration -Path c:\dsc0 -Wait -Force Start-Sleep 1 Start-DSCConfiguration -Wait -Force -UseExisting (Get-DSCConfigurationStatus).DurationInSeconds Start-DSCConfiguration -Path c:\dsc1 -Wait -Force Start-Sleep 1 Start-DSCConfiguration -Wait -Force -UseExisting (Get-DSCConfigurationStatus).DurationInSeconds Directory: C:\DSC0 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/16/2015 2:23 PM 76182 app1.mof Directory: C:\DSC1 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/16/2015 2:23 PM 5152 app1.mof 14 0
这是我的代码和最终testing结果。 查找示例花费大约80倍的时间来testing资源。 因此,将资源数量保持在最低水平并处理代码中的所有内容是值得的。