The xNetworking module is a part of the Windows PowerShell Desired State Configuration (DSC) Resource Kit, which is a collection of DSC Resources produced by the PowerShell Team. This module contains the xFirewall, xIPAddress and xDnsServerAddress resources. These DSC Resources allow configuration of a node’s IP Address, DNS Server Address, and Firewall Rules.
All of the resources in the DSC Resource Kit are provided AS IS, and are not supported through any Microsoft standard support program or service. The “x” in xNetworking stands for experimental, which means that these resources will be fix forward and monitored by the module owner(s).
Please leave comments, feature requests, and bug reports in the Q & A tab for this module.
If you would like to modify xNetworking module, feel free. When modifying, please update the module name, resource friendly name, and MOF class name (instructions below). As specified in the license, you may copy or modify this resource as long as they are used on the Windows Platform.
For more information about Windows PowerShell Desired State Configuration, check out the blog posts on the
PowerShell Blog (this
is a good starting point). There are also great community resources, such as
PowerShell.org
, or
PowerShell Magazine
. For more information on the DSC Resource Kit, check out
this blog post.
To install
xNetworking module
Unzip the content under $env:ProgramFiles\WindowsPowerShell\Modules folder
To confirm installation:
Run Get-DSCResource to see that
xFirewall, xIPAddress and xDnsServerAddress are among the DSC Resources listed
This module requires the latest version of PowerShell (v4.0, which ships in Windows 8.1 or Windows Server 2012R2). To easily use PowerShell 4.0 on older operating systems, install WMF 4.0 . Please read the installation instructions that are present on both the download page and the release notes for WMF 4.0.
Description
The xNetworking
module contains the xIPAddress, and DSC Resources. Instead of needing to know and remember the functionality and syntax for the IPAddress and DNS cmdlets, these DSC Resources allow you to easily configure and maintain your
networking settings by writing simple configurations. The
xFirewall
resource allows configuration of Firewall rules.
xIPAddress resource has following properties:
xDnsServerAddress resource has following properties:
xFirewall resource has following properties:
When making changes to these resources, we suggest the following practice:
Update the following names by replacing MSFT with your company/community name and replacing the “x” with "c" (short for "Community") or another prefix of your choice:
Update module and metadata information in the module manifest
Update any configuration that use these resources
We reserve resource and module names without prefixes ("x" or "c") for future use (e.g. "MSFT_xIPAddress" or "IPAddress"). If the next version of Windows Server ships with a "IPAddress" resource, we don't want to break any configurations that use any community modifications. Please keep a prefix such as "c" on all community modifications.
This configuration will set IP Address with some typical values for network interface alias = Ethernet.
configuration Sample_xIPAddress_FixedValue { param ( [string[]]$NodeName = 'localhost' ) Import-DscResource -Module xNetworking Node $NodeName { xIPAddress NewIPAddress { IPAddress = "2001:4898:200:7:6c71:a102:ebd8:f482" InterfaceAlias = "Ethernet" SubnetMask = 24 AddressFamily = "IPV6" } } }
configuration Sample_xIPAddress_FixedValue { param ( [string[]]$NodeName = 'localhost' ) Import-DscResource -Module xNetworking Node $NodeName { xIPAddress NewIPAddress { IPAddress = "2001:4898:200:7:6c71:a102:ebd8:f482" InterfaceAlias = "Ethernet" SubnetMask = 24 AddressFamily = "IPV6" } } }
This configuration will set IP Address along with default gateway on a network interface that is identified by its alias.
configuration Sample_xIPAddress_Parameterized { param ( [string[]]$NodeName = 'localhost', [Parameter(Mandatory)] [string]$IPAddress, [Parameter(Mandatory)] [string]$InterfaceAlias, [Parameter(Mandatory)] [string]$DefaultGateway, [int]$SubnetMask = 16, [ValidateSet("IPv4","IPv6")] [string]$AddressFamily = 'IPv4' ) Import-DscResource -Module xNetworking Node $NodeName { xIPAddress NewIPAddress { IPAddress = $IPAddress InterfaceAlias = $InterfaceAlias DefaultGateway = $DefaultGateway SubnetMask = $SubnetMask AddressFamily = $AddressFamily } } }
configuration Sample_xIPAddress_Parameterized { param ( [string[]]$NodeName = 'localhost', [Parameter(Mandatory)] [string]$IPAddress, [Parameter(Mandatory)] [string]$InterfaceAlias, [Parameter(Mandatory)] [string]$DefaultGateway, [int]$SubnetMask = 16, [ValidateSet("IPv4","IPv6")] [string]$AddressFamily = 'IPv4' ) Import-DscResource -Module xNetworking Node $NodeName { xIPAddress NewIPAddress { IPAddress = $IPAddress InterfaceAlias = $InterfaceAlias DefaultGateway = $DefaultGateway SubnetMask = $SubnetMask AddressFamily = $AddressFamily } } }
This configuration will set DNS Server Address on a network interface that is identified by its alias.
configuration Sample_xDnsServerAddress { param ( [string[]]$NodeName = 'localhost', [Parameter(Mandatory)] [string]$DnsServerAddress, [Parameter(Mandatory)] [string]$InterfaceAlias, [ValidateSet("IPv4","IPv6")] [string]$AddressFamily = 'IPv4' ) Import-DscResource -Module xNetworking Node $NodeName { xDnsServerAddress DnsServerAddress { Address = $DnsServerAddress InterfaceAlias = $InterfaceAlias AddressFamily = $AddressFamily } } }
configuration Sample_xDnsServerAddress { param ( [string[]]$NodeName = 'localhost', [Parameter(Mandatory)] [string]$DnsServerAddress, [Parameter(Mandatory)] [string]$InterfaceAlias, [ValidateSet("IPv4","IPv6")] [string]$AddressFamily = 'IPv4' ) Import-DscResource -Module xNetworking Node $NodeName { xDnsServerAddress DnsServerAddress { Address = $DnsServerAddress InterfaceAlias = $InterfaceAlias AddressFamily = $AddressFamily } } }
# DSC configuration for Firewall configuration Add_FirewallRule { param ( [string[]]$NodeName = 'localhost' ) Import-DSCResource -ModuleName xNetworking Node $NodeName { xFirewall Firewall { Name = "MyAppFirewallRule" ApplicationPath = "c:\windows\system32\MyApp.exe" Access = "Allow" } } }
# DSC configuration for Firewall # configuration Add_FirewallRuleToExistingGroup { param ( [string[]]$NodeName = 'localhost' ) Import-DSCResource -ModuleName xNetworking Node $NodeName { xFirewall Firewall { Name = "MyFirewallRule" DisplayName = "My Firewall Rule" DisplayGroup = "My Firewall Rule Group" Access = "Allow" } xFirewall Firewall1 { Name = "MyFirewallRule1" DisplayName = "My Firewall Rule" DisplayGroup = "My Firewall Rule Group" Ensure = "Present" Access = "Allow" State = "Enabled" Profile = ("Domain", "Private") } } }
# DSC configuration for Firewall # configuration Disable_AccessToApplication { param ( [string[]]$NodeName = 'localhost' ) Import-DSCResource -ModuleName xNetworking Node $NodeName { xFirewall Firewall { Name = "NotePadFirewallRule" DisplayName = "Firewall Rule for Notepad.exe" DisplayGroup = "NotePad Firewall Rule Group" Ensure = "Present" Access = "Block" Description = "Firewall Rule for Notepad.exe" ApplicationPath = "c:\windows\system32\notepad.exe" } } }
# DSC configuration for Firewall configuration Sample_xFirewall { param ( [string[]]$NodeName = 'localhost' ) Import-DSCResource -ModuleName xNetworking Node $NodeName { xFirewall Firewall { Name = "NotePadFirewallRule" DisplayName = "Firewall Rule for Notepad.exe" DisplayGroup = "NotePad Firewall Rule Group" Ensure = "Present" Access = "Allow" State = "Enabled" Profile = ("Domain", "Private") Direction = "OutBound" RemotePort = ("8080", "8081") LocalPort = ("9080", "9081") Protocol = "TCP" Description = "Firewall Rule for Notepad.exe" ApplicationPath = "c:\windows\system32\notepad.exe" Service = "WinRM" } } } Sample_xFirewall Start-DscConfiguration -Path Sample_xFirewall -Wait -Verbose -Force
1.0.0.0
Initial release with the following resources
2.0.0.0
Adding the xFirewall resource
2.1.0
2.1.1
Updated to fix issue with Get-DscConfiguration and xFirewall