Author Posts

July 14, 2017 at 1:00 pm

I set two params about IPv4 address, I want the params "$CNIPv4Address" and "$GWIPv4Address"can transmission to DSC configuration script just like below:

configuration dsc-node-config {

    param
  
    ( 
            [string[]]$NodeName,

            [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
            [ValidateScript({$_ -match [IPAddress]$_ })]  
            [string]$CNIPv4Address,

            [string[]]$CN_MACAddress,

            [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
            [ValidateScript({$_ -match [IPAddress]$_ })]  
            [string]$GWIPv4Address
     ) 

   Import-DSCResource -ModuleName xNetworking


    Node $NodeName {

        xNetAdapterName RenameCNNetAdapter
        {
            NewName = 'CN'
            MacAddress = "$CN_MACAddress"
        }

        xDhcpClient DisabledDhcpClient
        {
            State          = 'Disabled'
            InterfaceAlias = 'CN'
            AddressFamily  = 'IPv4'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'
        }

        xIPAddress NewCNIPv4Address
        {
            IPAddress      = '$CNIPv4Address'
            InterfaceAlias = 'CN'
            AddressFamily  = 'IPv4'
            PrefixLength = '24'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'

        }

        xDefaultGatewayAddress SetDefaultGateway
        {
            Address        = '$GWIPv4Address'
            InterfaceAlias = 'CN'
            AddressFamily  = 'IPv4'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'
        }

        xDNSServerAddress SetIPv4DNSAddress
        {
            Address = '1.1.1.1','2.2.2.2','3.3.3.3','4.4.4.4'
            AddressFamily = 'IPv4'
            InterfaceAlias = 'CN'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'
        }

   }
}

Run the above script and then run below PowerShell command with param

dsc-node-config -NodeName testserver -CNIPv4Address 45.117.22.189 -GWIPv4Address 45.117.22.1 -CN_MACAddress 00-50-56-9B-4C-F9

Only $CN_MACAddress param can work, both params "$CNIPv4Address" and "$GWIPv4Address" can't work.

Check the .MOF file as below can see just param "$CN_MACAddress" transmission to .MOF file, both both params "$CNIPv4Address" and "$GWIPv4Address" is still keep the variable in .MOF

instance of MSFT_xNetAdapterName as $MSFT_xNetAdapterName1ref
{
ResourceID = "[xNetAdapterName]RenameCNNetAdapter";
 MacAddress = "00-50-56-9B-4C-F9";
 ModuleVersion = "4.1.0.0";
 SourceInfo = "C:\\Users\\vif12066\\Desktop\\DSC\\New-DHCP-DSC-Config.ps1::39::9::xNetAdapterName";
 ModuleName = "xNetworking";
 NewName = "CN";

 ConfigurationName = "dsc-node-config";

};

instance of MSFT_xIPAddress as $MSFT_xIPAddress1ref
{
ResourceID = "[xIPAddress]NewCNIPv4Address";
 PrefixLength = 24;
 InterfaceAlias = "CN";
 AddressFamily = "IPv4";
 SourceInfo = "C:\\Users\\vif12066\\Desktop\\DSC\\New-DHCP-DSC-Config.ps1::53::9::xIPAddress";
 ModuleName = "xNetworking";
 IPAddress = "$CNIPv4Address";
 ModuleVersion = "4.1.0.0";

DependsOn = {

    "[xNetAdapterName]RenameCNNetAdapter"};

 ConfigurationName = "dsc-node-config";

};



instance of MSFT_xDefaultGatewayAddress as $MSFT_xDefaultGatewayAddress1ref
{
ResourceID = "[xDefaultGatewayAddress]SetDefaultGateway";
 AddressFamily = "IPv4";
 SourceInfo = "C:\\Users\\vif12066\\Desktop\\DSC\\New-DHCP-DSC-Config.ps1::63::9::xDefaultGatewayAddress";
 Address = "$GWIPv4Address";
 ModuleName = "xNetworking";
 InterfaceAlias = "CN";
 ModuleVersion = "4.1.0.0";

DependsOn = {

    "[xNetAdapterName]RenameCNNetAdapter"};

 ConfigurationName = "dsc-node-config";

};

Any guys who knows this issues is, please help on, many thanks.

July 14, 2017 at 7:16 pm

Hi Allen.Zhang

It's because you have used single quotes ' ' instead of double quotes " " around your $variable within the resource.

 xDefaultGatewayAddress SetDefaultGateway
        {
            Address        = '$GWIPv4Address'
            InterfaceAlias = 'CN'
            AddressFamily  = 'IPv4'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'

Should be

 
xDefaultGatewayAddress SetDefaultGateway
        {
            Address        = "$GWIPv4Address"
            InterfaceAlias = 'CN'
            AddressFamily  = 'IPv4'
            DependsOn = '[xNetAdapterName]RenameCNNetAdapter'

July 15, 2017 at 1:38 am

Hi Tommy, Many thanks for your help, it's work now !

I am so careless... 😉