locked
Param of IP address can't transmission to DSC configuration script file RRS feed

  • Question

  • 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. 

    Friday, July 14, 2017 12:30 AM

Answers

  • I am so careless. 

    From 

    Address = '$GWIPv4Address'

     IPAddress      = '$CNIPv4Address'

    to 

    Address = "$GWIPv4Address"

     IPAddress      = "$CNIPv4Address"

    Then works fine. 

    • Marked as answer by Allen.Zhang Tuesday, July 18, 2017 7:47 AM
    Tuesday, July 18, 2017 7:46 AM