Training
Module
Manage network service settings for Windows devices using PowerShell cmdlets - Training
This module covers the PowerShell modules and cmdlets that are used to configure network settings for Windows devices.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Important
This article describes features or settings that are in preview. The content is subject to change and may have dependencies on other features or services in preview.
Windows Firewall includes a functionality called dynamic keywords, which simplifies the configuration and management of Windows Firewall.
With dynamic keywords, you can define a set of IP address ranges, fully qualified domain names (FQDNs), and autoresolution options, to which one or more Firewall rules can refer.
To configure dynamic keywords, you can use:
Tip
Microsoft Intune offers a simplified management experience called reusable settings groups. For more information, see Add reusable settings groups to profiles for Firewall rules.
This article describes how to configure dynamic keywords using Windows PowerShell.
Dynamic keywords can be configured by defining a set of IP address ranges or FQDNs. Here are important things to consider when using FQDNs:
*
are supported for hosts, for example *.contoso.com
Two examples of FQDN rules are:
Note
Inbound FQDN rules aren't natively supported. However, it's possible to use pre-hydration scripts to generate inbound IP entries for the rules.
Caution
The default configuration of Blocked for Outbound rules can be considered for certain highly secure environments. However, the Inbound rule configuration should never be changed in a way that allows traffic by default.
In high security environments, an inventory of all apps should be maintained. Records should include whether an app requires network connectivity. Administrators should create new rules specific to each app that needs network connectivity, and push those rules centrally, using a device management solution.
The Windows Firewall FQDN feature uses the Network Protection external callout driver, to inspect DNS responses where the DNS query matches FQDN rules. Some important functions and limitations of the feature are:
The following are requirements for the FQDN feature:
4.18.2209.7
or later.
Tip
You can also download the ADMX file from there, follow the directions, and configure it via gpedit.msc for local testing.
This section provides some examples how to manage dynamic keywords using Windows PowerShell. A few important things to consider when using dynamic keywords are:
AutoResolve
objects that aren't yet resolvedHere's an example script to allow an FQDN from PowerShell. Replace the $fqdn
variable value with the FQDN you wish to block (line #1):
$fqdn = 'contoso.com'
$id = '{' + (new-guid).ToString() + '}'
New-NetFirewallDynamicKeywordAddress -id $id -Keyword $fqdn -AutoResolve $true
New-NetFirewallRule -DisplayName "allow $fqdn" -Action Allow -Direction Outbound -RemoteDynamicKeywordAddresses $id
Dynamic keyword addresses can be created with the AutoResolve
parameter set to $true
or $false
. If AutoResolve
is set to $true
, then Windows attempts to resolve the keyword to an IP address.
Here's an example script to block an FQDN from PowerShell. Replace the $fqdn
variable value with the FQDN you wish to block (line #1):
$fqdn = 'contoso.com'
$id = '{' + (new-guid).ToString() + '}'
New-NetFirewallDynamicKeywordAddress -id $id -Keyword $fqdn -AutoResolve $true
New-NetFirewallRule -DisplayName "block $fqdn" -Action Block -Direction Outbound -RemoteDynamicKeywordAddresses $id
This example shows how to display all dynamic keyword addresses that have the AutoResolve
parameter set to $true
and the associated resolved IP addresses.
Get-NetFirewallDynamicKeywordAddress -AllAutoResolve
Note
IP addresses will not populate until DNS query is observed.
The following sample scripts read the current Windows Firewall configuration, extract FQDN-based rules, and perform DNS resolution on each domain. The result is that the IP addresses for those rules get "prehydrated."
Get-NetFirewallDynamicKeywordAddress -AllAutoResolve |`
ForEach-Object {
if(!$_.Keyword.Contains("*")) {
Write-Host "Getting" $_.Keyword
resolve-dnsname -Name $_.Keyword -DNSOnly | out-null
}
}
A similar script can be used to perform DNS resolution using nslookup.exe
:
Get-NetFirewallDynamicKeywordAddress -AllAutoResolve |`
ForEach-Object {
if(!$_.Keyword.Contains("*")) {
Write-Host "Getting" $_.Keyword
nslookup $_.Keyword
}
}
If using nslookup.exe
, you must create an outbound firewall rule when using the block all outbound posture. Here's the command to create the outbound rule for nslookup.exe
:
$appName = 'nslookup'
$appPath = 'C:\Windows\System32\nslookup.exe'
New-NetFirewallRule -DisplayName "allow $appName" -Program $appPath -Action Allow -Direction Outbound -Protocol UDP -RemotePort 53
In the next example, a list of applications is parsed for FQDN evaluation. The FQDNs listed in the scripts were observed when inspecting traffic on the first launch of Microsoft Edge.
Important
This is not a complete list nor a recommendation. It's an example of how an application should be evaluated to ensure proper connectivity and function.
To learn more about Microsoft Edge requirements for Internet connectivity, see allowlist for Microsoft Edge endpoints.
$domains = @(
'*.microsoft.com',
'*.msftconnecttest.com',
'assets.msn.com',
'client.wns.windows.com',
'config.edge.skype.com',
'ctldl.windowsupdate.com',
'dns.msftncsi.com',
'login.live.com',
'ntp.msn.com'
)
foreach ($domain in $domains) {
$id = '{' + (New-Guid).ToString() + '}'
New-NetFirewallDynamicKeywordAddress -Id $id -Keyword $domain -AutoResolve $true
New-NetFirewallRule -DisplayName "allow $domain" -Action Allow -Direction Outbound -RemoteDynamicKeywordAddresses $id
}
For more information about the PowerShell cmdlets used to manage dynamic keywords, see:
For information about the API structure, see Firewall dynamic keywords.
Training
Module
Manage network service settings for Windows devices using PowerShell cmdlets - Training
This module covers the PowerShell modules and cmdlets that are used to configure network settings for Windows devices.