Hey,
I’m afraid that’s not true.
Remote Node:
I simplified the script to make a point:
Configuration TestLab
{
param ()
Import-DscResource –ModuleName "PSDesiredStateConfiguration"
Import-DscResource -ModuleName "xDhcpServer"
Node $AllNodes.Where{$_.Role -contains "Primary DC"}.NodeName {
xDhcpServerScope Scope {
Ensure = 'Absent'
Name = 'PowerShellScope'
ScopeID = '192.168.1.0'
IPStartRange = '192.168.1.10'
IPEndRange = '192.168.1.100'
SubnetMask = '255.255.255.0'
LeaseDuration = '00:08:00'
State = 'Active'
AddressFamily = 'IPv4'
}
}
}
#Create the MOF file based on the configuration above, using the MyData data-file
TestLab -ConfigurationData "C:\users\Administrator\Documents\MyLab\MyData.psd1"
Start-DscConfiguration -wait -force -path "C:\Users\Administrator\TestLab" -verbose
All I’m doing here is importing the xDhcpServer module and trying to remove the DHCP scope, which doesn’t exist because there isn’t even a DHCP server installed.
PS C:\Users\Administrator> C:\Users\Administrator\Documents\MyLab\MyScript2.ps1
Directory: C:\Users\Administrator\TestLab
Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 6/09/2018 11:16 2400 ZMTPSDSCLAB1.mof VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguratio
n'.
VERBOSE: An LCM method call arrived from computer ZMTPSDSCLAB2 with user sid S-1-5-21-2605852739-2061032376-1152750048-500.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Set ]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Resource ] [[xDhcpServerScope]Scope]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Test ] [[xDhcpServerScope]Scope]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Test ] [[xDhcpServerScope]Scope] in 0.0470 seconds.
PowerShell DSC resource MSFT_xDhcpServerScope failed to execute Test-TargetResource functionality with error message: Please ensure that the PowerShell module for role DHCPServer is installed
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : ZMTPSDSCLAB1
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Set ]
The SendConfigurationApply function did not succeed.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : ZMTPSDSCLAB1
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 1.829 seconds
If I run the exact same script but instead of removing a non-existent scope, adding the Dhcp-server, it works, which proves it’s not a missing dsc-resource issue.
Configuration TestLab
{
param ()
Import-DscResource –ModuleName "PSDesiredStateConfiguration"
Import-DscResource -ModuleName "xDhcpServer"
Node $AllNodes.Where{$_.Role -contains "Primary DC"}.NodeName {
WindowsFeature dhcp-server {
Name = 'DHCP'
Ensure = 'Present'
IncludeAllSubFeature = $true
}
WindowsFeature RSAT-Dhcp {
Name = 'RSAT-DHCP'
Ensure = 'Present'
DependsON = '[WindowsFeature]dhcp-server'
}
}
}
#Create the MOF file based on the configuration above, using the MyData data-file
TestLab -ConfigurationData "C:\users\Administrator\Documents\MyLab\MyData.psd1"
Start-DscConfiguration -wait -force -path "C:\Users\Administrator\TestLab" -verbose
PS C:\Users\Administrator> C:\Users\Administrator\Documents\MyLab\MyScript2.ps1
Directory: C:\Users\Administrator\TestLab
Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 6/09/2018 11:26 2878 ZMTPSDSCLAB1.mof
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguratio
n'.
VERBOSE: An LCM method call arrived from computer ZMTPSDSCLAB2 with user sid S-1-5-21-2605852739-2061032376-1152750048-500.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Set ]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Resource ] [[WindowsFeature]dhcp-server]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Test ] [[WindowsFeature]dhcp-server]
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] The operation 'Get-WindowsFeature' started: DHCP
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] The operation 'Get-WindowsFeature' succeeded: DHCP
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Test ] [[WindowsFeature]dhcp-server] in 0.4840 seconds.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Set ] [[WindowsFeature]dhcp-server]
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Installation started...
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Continue with installation?
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Prerequisite processing started...
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Prerequisite processing succeeded.
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Installation succeeded.
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]dhcp-server] Successfully installed the feature DHCP.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Set ] [[WindowsFeature]dhcp-server] in 24.9220 seconds.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Resource ] [[WindowsFeature]dhcp-server]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Resource ] [[WindowsFeature]RSAT-Dhcp]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Test ] [[WindowsFeature]RSAT-Dhcp]
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] The operation 'Get-WindowsFeature' started: RSAT-DHCP
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] The operation 'Get-WindowsFeature' succeeded: RSAT-DHCP
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Test ] [[WindowsFeature]RSAT-Dhcp] in 0.2190 seconds.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ Start Set ] [[WindowsFeature]RSAT-Dhcp]
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Installation started...
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Continue with installation?
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Prerequisite processing started...
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Prerequisite processing succeeded.
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Installation succeeded.
VERBOSE: [ZMTPSDSCLAB1]: [[WindowsFeature]RSAT-Dhcp] Successfully installed the feature RSAT-DHCP.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Set ] [[WindowsFeature]RSAT-Dhcp] in 7.9680 seconds.
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Resource ] [[WindowsFeature]RSAT-Dhcp]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Set ]
VERBOSE: [ZMTPSDSCLAB1]: LCM: [ End Set ] in 33.8280 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 36.21 seconds
If right after this, I remove the dhcp-service and remove the scope, that still doesn’t exist, it will give the same error.
DSC is only idempotent if you write it that way, not by design.