Powershell – How to apply xNetworking xIPAddress Desired State Configuration (DSC)

dscpowershell

Using Windows Server 2012 R2.

The goal is to set the IPv4 address of a server. As DSC correctly states in the verbose message below, the Expected [ip is] 192.168.0.203, [while the] actual [ip is] 192.168.0.205

The following error message:

Start-DscConfiguration -Path .\BasicServer -Verbose -Wait -Force

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' =
MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer ComputerName with user sid S-1-5-21-139086020-2308268882-217435134-1104.
VERBOSE: [ComputerName]: LCM:  [ Start  Set      ]
VERBOSE: [ComputerName]: LCM:  [ Start  Resource ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]: LCM:  [ Start  Test     ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Checking the IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] IPAddress not correct. Expected 192.168.0.203, actual 192.168.0.205
VERBOSE: [ComputerName]: LCM:  [ End    Test     ]  [[xIPAddress]IPAddress]  in 0.0310 seconds.
VERBOSE: [ComputerName]: LCM:  [ Start  Set      ]  [[xIPAddress]IPAddress]
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Checking the IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] IPAddress not correct. Expected 192.168.0.203, actual 192.168.0.205
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Setting IPAddress ...
VERBOSE: [ComputerName]:                            [[xIPAddress]IPAddress] Instance DefaultGateway already exists
VERBOSE: [ComputerName]: LCM:  [ End    Set      ]  [[xIPAddress]IPAddress]  in 0.0620 seconds.
PowerShell DSC resource MSFT_xIPAddress  failed to execute Set-TargetResource functionality with error message: Can not set or find valid IPAddress using
InterfaceAlias Ethernet and AddressFamily IPv4
+ CategoryInfo          : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName        : ComputerName.domain.com

The SendConfigurationApply function did not succeed.
+ CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName        : ComputerName.domain.com

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.268 seconds

… is thrown when applying the following xNetworking DSC configuration:

Import-DscResource -Module xNetworking

Node $NodeFQDN {
xIPAddress IPAddress {
    InterfaceAlias = "Ethernet"
    IPAddress = $IPv4
    AddressFamily = "IPV4"
    DefaultGateway = '192.168.0.1'
    SubnetMask = 24
}}

where $IPv4 = '192.168.0.203'.

I have noticed that the Local Configuration Manager is capable of Test-DSCConfiguration, only unable to apply any IP related changes. I have tested this by running the configuration above on the system while the IP is already correctly set.

The message "Can not set or find valid IPAddress using InterfaceAlias Ethernet and AddressFamily IPv4" is confusing since the LCM has obviously been able to find the the adapter during the Test-DSCConfiguration operation.

Any clues as to why the Local Configuration Manager is unable to apply the configuration? What am I not seeing?

Best Answer

The solution was to remove the default gateway from the configuration: DefaultGateway = '192.168.0.1'

It appears that if there are any configurations in addition to the basic ones (IPAddress, InterfaceAlias, SubnetMask, AddressFamily), DSC will focus on the additional items and consider the basic ones as references. Consider the following:

xIPAddress IPAddress {
    InterfaceAlias = 'Ethernet'
    IPAddress = '192.168.0.203'
    AddressFamily = 'IPV4'
    SubnetMask = 24
}

The above configuration will set the IP address to 192.168.0.203.

 xIPAddress IPAddress {
    InterfaceAlias = 'Ethernet'
    IPAddress = '192.168.0.203'
    AddressFamily = 'IPV4'
    SubnetMask = 24
    DefaultGateway = '192.168.0.1'
}

The above configuration will find an adapter named 'Ethernet' with an IP address of 192.168.0.203 and configure its DefaultGateway to 192.168.0.1. In my Question the Local Configuration Manager was unable to locate such an adapter. I was attempting to set the IP and the Gateway simultaneously.

This discovery leads me to understand that setting the IP and configuring other adapter properties cannot be done in a single configuration. This kind of eliminates the idea of using a single (yes, only 1) script to configure a server end-to-end.

Am I getting this right?

p.s. I have also experienced configurations appending the new IP instead of replacing. Won't get into that now, but very interesting behavior...