SkillPilotAI

PowerShell NetSecurity module (7/7)

The last part of the NetSecurity module: the remaining Set cmdlets (security/service filters, global firewall settings, IPsec DoS, crypto sets, auth sets and rules), the read-only Show cmdlets, and Sync/Update that keep IPsec rule addresses current. Knowing per-profile vs global settings is a classic interview point.

223.1 What it does, where it runs

  • Built into Windows 10/11 and Windows Server; PowerShell 5.1 and 7.
  • Set, Sync and Update change firewall/IPsec policy and need an Administrator PowerShell.
  • Show-* changes nothing but prints the whole policy, so it is still sensitive on a managed machine.
  • The module has 20 Set cmdlets; on the office PC only Get-Command and Get-Help ran, the rest is from Microsoft Learn.
PowerShell
Get-Command -Module NetSecurity -Verb Set |  Measure-ObjectGet-Help Set-NetFirewallSetting
Output
$ Get-Command -Module NetSecurity -Verb Set | Measure-ObjectCount    : 20$ Get-Help Set-NetFirewallSetting   (trimmed)Synopsis : Set-NetFirewallSetting [-PolicyStore <string>] [-GPOSession <string>] [-Exemptions           <TrafficExemption>] [-EnableStatefulFtp <GpoBoolean>] [-EnableStatefulPptp <GpoBoolean>]           [-RemoteMachineTransportAuthorizationList <string>] ...           [-CertValidationLevel <CRLCheck>] [-AllowIPsecThroughNAT <IPsecThroughNAT>]           [-MaxSAIdleTimeSeconds <uint32>] [-KeyEncoding <KeyEncoding>] [-EnablePacketQueuing           <PacketQueuing>] [-CimSession <CimSession[]>] [-ThrottleLimit <int>] [-AsJob] [-PassThru]           [-WhatIf] [-Confirm] [<CommonParameters>]ModuleName : NetSecurityremarks : Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only          partial help.

223.2 How it works: a global setting

IPsec Require, then -Exemptions Icmp
  1. 1.Server 192.168.1.10 has an IPsec rule: Require inbound authentication

  2. 2.Client 192.168.1.20 pings without IPsec

  3. 3.Windows Firewall drops it: not authenticated, client sees Request timed out.

  4. 4.Admin: Set-NetFirewallSetting -Exemptions Icmp

  5. 5.ICMP is exempt from IPsec requirements (global, every profile)

  6. 6.Next ping passes the firewall and reaches the server

The change is in the computer-wide setting, not in any one rule.

223.3 Set-NetFirewallSecurityFilter (10) + Set-NetFirewallServiceFilter (5)

  • Security filter = a rule's security conditions: -Authentication, -Encryption, -OverrideBlockRules, -LocalUser, -RemoteUser, -RemoteMachine.
  • Service filter links a rule to a Windows service (-Service).
  • Both take the filter object from the pipeline.
PowerShell
Get-NetFirewallRule `  -DisplayGroup "*Printer*" |  Get-NetFirewallSecurityFilter |  Set-NetFirewallSecurityFilter `  -Authentication RequestGet-NetFirewallRule `  -Group "@FirewallAPI.dll,-30502" |  Get-NetFirewallServiceFilter -Service Any |  Set-NetFirewallServiceFilter `  -Service Ssdpsrv

223.4 Set-NetFirewallSetting (17)

Settings that are the same whichever network profile is active.

OptionValuesMeaning
-ExemptionsNone, NeighborDiscovery, Icmp, RouterDiscovery, Dhcp, NotConfiguredTraffic exempt from IPsec requirements
-EnableStatefulFtp / -EnableStatefulPptpGpoBooleanHow the extra FTP/PPTP connections are handled
-CertValidationLevelNone, AttemptCrlCheck, RequireCrlCheckCertificate revocation list check
-AllowIPsecThroughNATNone, Server, BothIPsec across NAT
-MaxSAIdleTimeSeconds300..3600After how long an idle SA is deleted
-KeyEncodingUTF16, UTF8Preshared key encoding
-EnablePacketQueuingNone, Inbound, ForwardPacket queuing
Authorization listsRemoteMachine/RemoteUser Tunnel/Transport listsAllowed computers and users at the IPsec layer
PowerShell
Get-NetFirewallSetting `  -PolicyStore corp.contoso.com/gpo_name |  Set-NetFirewallSetting `  -Exemptions RouterDiscovery

223.5 IPsec Set cmdlets

CmdletOptionsWhat it changes / docs example
Set-NetIPsecDospSetting27IPv6 DoS protection public -> internal; needs at least 1 public + 1 private interface; MaxStateEntries default 75000
Set-NetIPsecMainModeCryptoSet15Main Mode crypto; DA Client group -MaxMinutes 240 (0..2879)
Set-NetIPsecQuickModeCryptoSet12Quick Mode proposals (AES128 + AESGMAC128), -PerfectForwardSecrecyGroup
Set-NetIPsecMainModeRule19Enable DA Client Main Mode rules; back to Default crypto set via dot notation
Set-NetIPsecPhase1AuthSet11Computer authentication; new root certificate proposal
Set-NetIPsecPhase2AuthSet11User authentication; -NewDisplayName
Set-NetIPsecRule39-Mode, -InboundSecurity/-OutboundSecurity, -KeyModule, ports, addresses, tunnel endpoints, auth sets
PowerShell
Set-NetIPsecDospSetting -Name PubNet-CorpNet `  -PublicInterfaceAliases PubNet2$dosPSetting = Get-NetIPsecDospSetting `  -Name PubNet-CorpNet$dosPSetting.IpV6IPsecUnauthDscp = "Disabled" Set-NetIPsecMainModeCryptoSet `  -DisplayGroup "DA Client" -MaxMinutes 240$crypto1 = `  New-NetIPsecQuickModeCryptoProposal `  -Encryption AES128 -ESPHash AESGMAC128Set-NetIPsecQuickModeCryptoSet -DisplayName `  "Exchange HIPAA Server, 80 <-> Any ..." `  -Proposals $crypto1,$crypto2
PowerShell
Set-NetIPsecMainModeRule `  -DisplayGroup "DA Client" -Enabled True$rule = Get-NetIPsecMainModeRule `  -DisplayName "Tunnel Mode - (DA Client)"$rule.MainModeModeCryptoSet = "Default"Set-NetIPsecMainModeRule -InputObject $ruleSet-NetIPsecPhase2AuthSet -DisplayGroup `  "Authenticate with Certificates" `  -NewDisplayName `  "User Authentication Certificates" $kerbComputer = New-NetIPsecAuthProposal `  -Kerberos -Machine$Phase1AuthSet = New-NetIPsecPhase1AuthSet `  -DisplayName "Computer Kerb Auth" `  -Proposal $kerbComputerSet-NetIPsecRule `  -DisplayName "SecureNet Rule" `  -Phase1AuthSet $Phase1AuthSet.Name
  • Dot notation pattern: get the object, change a property, then commit it with Set-... -InputObject.
  • -InboundSecurity/-OutboundSecurity: None, Request or Require; -Mode: Tunnel or Transport.
  • -PerfectForwardSecrecyGroup chooses the Diffie-Hellman group (None, DH1, DH2, DH14, DH19, DH20, DH24, SameAsMainMode).

223.6 Show-, Sync- and Update- cmdlets

  • Show-NetFirewallRule / Show-NetIPsecRule: print every rule with its associated objects; -PolicyStore ActiveStore = all stores that apply to the computer.
  • Update-NetFirewallDynamicKeywordAddress: updates a dynamic keyword's addresses; -Append $True adds instead of replacing; braces around the -Id GUID are required.
  • Sync-NetIPsecRule (42): resolves -Domains/-Servers via -DnsServers and updates rule endpoints; -EndpointType Endpoint1 (local) or Endpoint2 (remote); pass -Confirm.
  • Update-NetIPsecRule (8): directly adds/deletes IPv4/IPv6 addresses in one rule; the script from Get-DAPolicyChange uses it.
Sync-NetIPsecRule: IPs from DNS, then rule update
  1. 1.Admin runs Sync-NetIPsecRule on a DirectAccess IPsec rule

  2. 2.DNS query for -Domains and -Servers to 192.168.1.53

  3. 3.DNS returns the current IPs

  4. 4.Cmdlet compares them with the rule's existing addresses

  5. 5.Delta computed: Add / Delete

  6. 6.Rule endpoints updated in the GPO (server_GPO)

PowerShell
Show-NetFirewallRule -PolicyStore ActiveStoreShow-NetIPsecRule -PolicyStore ActiveStoreUpdate-NetFirewallDynamicKeywordAddress `  -Id `  "{01234567-89ab-cdef-0123-456789abcdef}" `  -Addresses 192.0.0.1 -Append $TrueSync-NetIPsecRule `  -PolicyStore $serverPolicyStore `  -IPsecRuleName $serverRuleName `  -EndpointType endpoint1 `  -Domains $domains -Servers $servers `  -DnsServers $primaryDns64 `  -AddressType IPv6 -ConfirmUpdate-NetIPsecRule `  -IPsecRuleName "IPsec Rule" -Action Add `  -IPv4addresses $IPv4list `  -IPv6addresses $IPv6list `  -EndpointType Endpoint2 `  -PolicyStore domain.contoso.com/sample_gpo

223.7 Linux equivalent: chain policy and nft replace

  • The closest Linux idea to a global setting is a chain's default policy: it applies to every packet no rule matches.
  • Lab: server 192.168.243.10 with NET_ADMIN, our own inet table n223 with policy drop.
  • nft replace rule keeps the handle and changes only the condition, like Set-NetFirewallPortFilter.
Terminal
# n223.nft (server, NET_ADMIN)table inet n223 {  chain input {    type filter hook input priority 0    policy drop    tcp dport 22 counter accept  }}nft -f /root/n223.nft# client:ping -c 2 -W 1 192.168.243.10 | tail -2# server: default action drop -> acceptnft chain inet n223 input '{ policy accept; }'
Output
[client] $ ping -c 2 -W 1 192.168.243.10 | tail -22 packets transmitted, 0 received, 100% packet loss, time 1027ms$ nft chain inet n223 input '{ policy accept; }'$ nft list chain inet n223 inputtable inet n223 {	chain input {		type filter hook input priority filter; policy accept;		tcp dport 22 counter packets 0 bytes 0 accept	}}[client] $ ping -c 2 -W 1 192.168.243.10 | tail -22 packets transmitted, 2 received, 0% packet loss, time 1007ms
Terminal
nft chain inet n223 input '{ policy drop; }'nc -zv -w 2 192.168.243.10 2222nft replace rule inet n223 input handle 2 \  tcp dport 2222 counter acceptnft -a list table inet n223nc -zv -w 2 192.168.243.10 2222nft delete table inet n223
Output
[client] $ nc -zv -w 2 192.168.243.10 2222nc: connect to 192.168.243.10 port 2222 (tcp) timed out: Operation in progress$ nft replace rule inet n223 input handle 2 tcp dport 2222 counter accept$ nft -a list table inet n223table inet n223 { # handle 2	chain input { # handle 1		type filter hook input priority filter; policy drop;		tcp dport 2222 counter packets 0 bytes 0 accept # handle 2	}}[client] $ nc -zv -w 2 192.168.243.10 2222Connection to 192.168.243.10 2222 port [tcp/*] succeeded!		tcp dport 2222 counter packets 4 bytes 216 accept # handle 2

223.8 Comparison: Set-NetFirewallSetting vs Set-NetFirewallProfile

PointSet-NetFirewallProfileSet-NetFirewallSetting
ScopePer profile (Domain, Private, Public)Global, same for every profile
Typical options-Enabled, -DefaultInboundAction, logging-Exemptions, -MaxSAIdleTimeSeconds, -CertValidationLevel
ExampleDomain profile default inbound BlockExempt ICMP from IPsec requirements
Linux analogyPer-chain policyGlobal defaults of the ruleset

223.9 Common mistakes

  • Thinking -WhatIf is always safe: the policy is not changed, but real rules are read and their names appear in the output; get approval on a managed PC.
  • Using Set-NetFirewallProfile for an IPsec exemption; exemptions are global, so it is Set-NetFirewallSetting.
  • Running Show-NetFirewallRule on an office PC: it reveals the whole policy.
  • Missing braces around the GUID in Update-NetFirewallDynamicKeywordAddress -Id.

223.10 Interview tips

  • Set-NetFirewallProfile = per profile (default inbound action); Set-NetFirewallSetting = global (exemptions, SA idle time).
  • Exempt ICMP on every profile: Set-NetFirewallSetting -Exemptions Icmp in an admin shell.
  • IPsec policy: Set-NetIPsecRule plus the crypto set and auth set cmdlets; Show-NetFirewallRule shows the whole policy expanded.
  • Sync-NetIPsecRule keeps DirectAccess rule IPs current from DNS; Update-NetIPsecRule edits addresses directly.
  • Whole module pattern: a rule is one object; filters, profiles and IPsec sets are objects connected to it.