PowerShell NetEventPacketCapture module
NetEventPacketCapture is Windows' built-in packet capture from PowerShell: create a session, add providers and filters, start, reproduce, stop, remove, and analyse the .etl file. It lets you capture one IP on a server without installing Wireshark.
229.1 What it does, where it runs
- Built into Windows 10/11 and Windows Server; PowerShell 5.1 and 7.
- Session + providers; the result is saved to an .etl file.
- The module has 35 cmdlets; session cmdlets need an admin PowerShell.
- No NetEvent* cmdlet ran on the office PC (a capture would record office traffic); examples are from Microsoft Learn and a tcpdump lab.
Get-Command -Module NetEventPacketCapture | Measure-ObjectGet-Help New-NetEventSession$ Get-Command -Module NetEventPacketCapture | Measure-ObjectCount : 35$ Get-Help New-NetEventSessionNAME New-NetEventSessionSYNTAX New-NetEventSession [-Name] <string> [-CaptureMode {RealtimeRPC | SaveToFile | RealtimeLocal}] [-LocalFilePath <string>] [-MaxFileSize <uint32>] [-MaxNumberOfBuffers <byte>] [-TraceBufferSize <uint32>] [-CimSession <CimSession[]>] [-ThrottleLimit <int>] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]ALIASES NoneREMARKS Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.229.2 How it works: session + provider filter
- Step 1
1.Windows PC runs Session01 (.etl)
- Step 2
2.Packet capture provider filter: 192.168.249.10
- Step 3
3.Browser HTTP GET goes via the switch to the web server 192.168.249.10
- Step 4
4.Provider writes a copy to Session01.etl
- Step 5
5.Print job to printer 192.168.249.30 is delivered normally
- Step 6
6.No filter match: not saved in the file
- Step 1
1.New-NetEventSession -LocalFilePath
- Step 2
2.Add-NetEventPacketCaptureProvider (filters)
- Step 3
3.Start-NetEventSession
- Step 4
4.Reproduce the problem
- Step 5
5.Stop-NetEventSession, then Remove-NetEventSession
- Step 6
6.Convert .etl to pcapng (pktmon etl2pcap) and open in Wireshark
Only one session can exist at a time.
229.3 New-NetEventSession (7) + Set-NetEventSession (10)
| Option | Meaning / default |
|---|---|
| -CaptureMode | SaveToFile (.etl); RealtimeRPC / RealtimeLocal need extra software for live display |
| -LocalFilePath | Default %LocalAppData%\Temp\NetTrace.etl |
| -MaxFileSize | MB, default 250, 0 = no max; when full the oldest events are discarded |
| -MaxNumberOfBuffers / -TraceBufferSize | Buffer tuning; TraceBufferSize in KB, max 1024 |
| Common | -AsJob, -CimSession (remote), -ThrottleLimit, -Confirm, -WhatIf |
New-NetEventSession -Name "Session38"Set-NetEventSession -LocalFilePath ` 'C:\WINDOWS\Temp\Trace.etl'- Set-NetEventSession changes settings later; on a running session they apply after a restart.
229.4 Packet capture provider (13 / 17 options)
- Only one packet capture provider at a time per session.
- -IpAddresses / -IpProtocols filters; several addresses are combined with logical OR.
- -LinkLayerAddress (MAC), -EtherType 0800 IPv4, 86DD IPv6, 0806 ARP.
- -TruncationLength keeps the first 128 bytes of each packet by default.
- -CaptureType Physical | Switch | BothPhysicalAndSwitch (physical NIC or Hyper-V switch); -VmCaptureDirection Ingress | Egress.
New-NetEventSession -Name "Session01"Add-NetEventPacketCaptureProvider ` -SessionName "Session01"Set-NetEventPacketCaptureProvider ` -SessionName "Session01" ` -IpAddresses 182.168.0.1 -IpProtocol 6229.5 Start, Get, Stop, Remove
New-NetEventSession -Name "Session38"Add-NetEventProvider ` -Name "Microsoft-Windows-TCPIP" ` -SessionName "Session38"Start-NetEventSession -Name "Session38"Get-NetEventSession -Name "Session38"Stop-NetEventSession -Name "Session38"Remove-NetEventSession -Name "Session38"# convert the .etl (pktmon docs)pktmon etl2pcap <file> [--out <name>] [--drop-only] [--component-id <id>]- Without a provider no events are logged; a running session cannot be started again.
- Get-NetEventSession shows the settings and whether the session is running.
- Stop ends the capture but the session and its config remain; Remove-NetEventSession deletes it so a new one can be created.
- Get/Remove-NetEventPacketCaptureProvider show or delete the provider and its settings.
229.6 Other providers and filters
| Family | Cmdlets (options) | Purpose / docs example |
|---|---|---|
| ETW provider | Add (6) / Get (5) / Set (9) / Remove (4) -NetEventProvider | Windows ETW events, e.g. Microsoft-Windows-TCPIP; -Level 0x5 Verbose ... 0x3 Warning ... 0x1 Critical |
| Network adapter | Add (3) / Get (4) / Remove (5) -NetEventNetworkAdapter | Capture only on one NIC (Ethernet01); -PromiscuousMode $true |
| VM network adapter | Add (2) / Get (4) / Remove (4) -NetEventVmNetworkAdapter | Limit to one VM's adapter on a Hyper-V host |
| VM switch | Add (2) / Get (4) / Remove (4) -NetEventVmSwitch | A whole Hyper-V virtual switch as the filter |
| VM switch provider | Add (7) / Get (3) / Set (10) / Remove (4) | Switch events; -PortIds 20 |
| VFP provider | Add (18) / Get (3) / Set (21) / Remove (4) | Virtual Filtering Platform flows; IP, MAC, ports, VLAN, tenant filters |
| WFP capture provider | Add (9) / Get (3) / Set (12) / Remove (4) | Windows Filtering Platform (firewall layer); -CaptureLayerSet IPv4Inbound, IPv6Inbound |
Add-NetEventNetworkAdapter -Name "Ethernet01" ` -PromiscuousMode $trueSet-NetEventProvider ` -Name "Microsoft-Windows-TCPIP" -Level 3Add-NetEventWFPCaptureProvider ` -SessionName "WFPCapture"Set-NetEventWFPCaptureProvider ` -SessionName "WFPCapture" -CaptureLayerSet ` IPv4Inbound, IPv6Inbound ` -IPAddresses "127.0.0.1", "::1"Start-NetEventSession -Name "WFPCapture"ping 127.0.0.1Stop-NetEventSession -Name "WFPCapture"Remove-NetEventSession -Name "WFPCapture"229.7 Linux equivalent: tcpdump lab
| Windows | tcpdump / tshark |
|---|---|
| New-NetEventSession -LocalFilePath | tcpdump -w /tmp/cap1.pcap |
| Provider filter -IpAddresses | 'host 192.168.249.10 and (icmp or tcp port 80)' |
| -TruncationLength 128 | -s 128 |
| Get-NetEventSession (running?) | ps shows the tcpdump process |
| Stop-NetEventSession | kill -INT <pid> |
| -MaxFileSize (oldest discarded) | Ring buffer -C 1 -W 3 |
| .etl -> Wireshark | tshark -r / capinfos |
tcpdump -i eth0 -p -s 128 \ -w /tmp/cap1.pcap \ 'host 192.168.249.10 and (icmp or tcp port 80)' \ > /tmp/cap1.log 2>&1 &echo $! > /tmp/cap1.pidping -c 2 192.168.249.10 | tail -2curl -s http://192.168.249.10/kill -INT $(cat /tmp/cap1.pid)cat /tmp/cap1.log; ls -l /tmp/cap1.pcaptshark -r /tmp/cap1.pcap[cap]$ ps -o pid,args | grep '[t]cpdump' 26 tcpdump -i eth0 -p -s 128 -w /tmp/cap1.pcap host 192.168.249.10 and (icmp or tcp port 80)hello-n229tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 128 bytes16 packets captured16 packets received by filter0 packets dropped by kernel-rw-r--r-- 1 root root 1615 Nov 9 15:09 /tmp/cap1.pcap[cap]$ tshark -r /tmp/cap1.pcap 1 0.000000 192.168.249.20 → 192.168.249.10 ICMP 98 Echo (ping) request id=0x7d71, seq=1/256, ttl=64 2 0.000109 192.168.249.10 → 192.168.249.20 ICMP 98 Echo (ping) reply id=0x7d71, seq=1/256, ttl=64 (request in 1) 5 1.083370 192.168.249.20 → 192.168.249.10 TCP 74 58326 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=3767928250 TSecr=0 WS=1024 6 1.083451 192.168.249.10 → 192.168.249.20 TCP 74 80 → 58326 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=3698543055 TSecr=3767928250 WS=1024 7 1.083473 192.168.249.20 → 192.168.249.10 TCP 66 58326 → 80 [ACK] Seq=1 Ack=1 Win=64512 Len=0 TSval=3767928250 TSecr=3698543055 8 1.083651 192.168.249.20 → 192.168.249.10 HTTP 143 GET / HTTP/1.1 [Packet size limited during capture] 10 1.103641 192.168.249.10 → 192.168.249.20 HTTP 251 HTTP/1.0 200 OK [Packet size limited during capture]tcpdump -i eth0 -p -w /tmp/ring.pcap \ -C 1 -W 3 \ 'host 192.168.249.10 and tcp port 80' \ > /tmp/ring.log 2>&1 &for i in 1 2; do curl -s -o /dev/null \ -w 'download %{size_download} bytes\n' \ http://192.168.249.10/big.bin; donecapinfos -c /tmp/ring.pcap0 \ /tmp/ring.pcap1 /tmp/ring.pcap2download 3000000 bytesdownload 3000000 bytes389 packets captured389 packets received by filter0 packets dropped by kernel-rw-r--r-- 1 root root 1012600 Nov 9 15:09 /tmp/ring.pcap0-rw-r--r-- 1 root root 1053766 Nov 9 15:09 /tmp/ring.pcap1-rw-r--r-- 1 root root 841484 Nov 9 15:09 /tmp/ring.pcap2File name: /tmp/ring.pcap0Number of packets: 60File name: /tmp/ring.pcap1Number of packets: 63File name: /tmp/ring.pcap2Number of packets: 46- 389 packets captured but the three ring files keep only 169: old files were overwritten, just like MaxFileSize discarding the oldest events.
- The HTTP lines say 'Packet size limited during capture' because of the 128-byte snap length.
229.8 Common mistakes
- Long capture on default settings: at 250 MB the oldest events (the start of the problem) are discarded; raise -MaxFileSize or add a filter.
- Thinking Stop removes the session: config stays and only one session can exist, so run Remove-NetEventSession.
- Starting a session with no provider: nothing is logged.
- Capturing on an office PC without approval: it records office traffic.
229.9 Interview tips
- Capture one IP without Wireshark: admin PowerShell, New-NetEventSession -LocalFilePath, Add-NetEventPacketCaptureProvider -IpAddresses -TruncationLength, Start.
- Reproduce, then Stop and Remove (one session at a time).
- Convert .etl to pcapng (pktmon etl2pcap) and analyse in Wireshark.
- Know the provider families: packet capture, ETW, NIC/VM adapter, VM switch, VFP, WFP.
- Linux equivalent: tcpdump -w with a filter and -s, ring buffer -C/-W, tshark -r.