PowerShell RemoteAccess module (1/5)
The RemoteAccess module manages RRAS (Routing and Remote Access Service), the Windows Server role for VPN, routing/BGP, DirectAccess and RADIUS login checks. Part 1 covers all the Add- cmdlets, and the lab runs real BGP on Linux with FRRouting.
255.1 Why is it used?
- Remote users connect to the office over VPN (IKEv2 / SSTP 443) and get an IP from a pool.
- RRAS checks logins with a RADIUS server (NPS) instead of local accounts.
- BGP exchanges routes with branch routers so new networks are learned automatically.
- DirectAccess gives domain-joined laptops an always-on connection with no user action.
- Runs only on Windows Server; office PC answer was Count 0, so syntax/output come from Microsoft Learn.
Get-Command -Module RemoteAccess ` -ErrorAction SilentlyContinue | Measure-ObjectPS C:\> Get-Command -Module RemoteAccess -ErrorAction SilentlyContinue | Measure-Object Count : 0255.2 How it works
- Step 1
1.Remote user at home builds a VPN tunnel (IKEv2 / SSTP) over the internet to RRAS 131.107.0.10
- Step 2
2.RRAS sends Access-Request to NPS / RADIUS 10.1.2.1
- Step 3
3.RADIUS answers Access-Accept
- Step 4
4.Laptop gets 40.1.1.10 from the VPN pool
- Step 5
5.Traffic goes on to the app server in Corp LAN 10.1.0.0/16
- Step 6
6.Branch router (BGP peer) advertises 10.2.0.0/16 in a BGP UPDATE
| Common parameter | Meaning |
|---|---|
| -AsJob | Runs as a background job |
| -CimSession Server01 | Runs on a remote computer |
| -ThrottleLimit 8 | Max concurrent operations |
| -Confirm / -WhatIf | Ask first / only show what would happen |
255.3 Add-BgpRouter and Add-BgpPeer
- Step 1
1.Add-BgpRouter gives each router an ASN + BGP identifier (router1 AS 65001, router2 AS 65002)
- Step 2
2.Add-BgpPeer: both connect on TCP 179
- Step 3
3.They exchange OPEN messages (OPEN AS 65001)
- Step 4
4.Session becomes Established
- Step 5
5.router1 sends UPDATE with its custom routes 10.255.1-3.0/24
- Step 6
6.router2 stores them in its BGP table
- Add-BgpRouter: -BgpIdentifier (IPv4 router ID) and -LocalASN required.
- -RouteReflector Enabled -ClusterId makes an iBGP route reflector; -RoutingDomain selects a multi-tenant router.
- Add-BgpPeer: -Name, -LocalIPAddress, -PeerIPAddress, -PeerASN required; a new peer goes to Connecting.
- -OperationMode Server + -PeeringMode Manual keeps the peer Stopped (waits for the other side / manual start).
- -HoldTimeSec = timeout, -MaxAllowedPrefix = prefix limit, -Weight, -RouteReflectorClient.
Add-BgpRouter -BgpIdentifier 10.1.1.10 -LocalASN 64522 -PassThru Add-BgpPeer -Name "RedTenantSite1" -LocalIPAddress 192.168.1.10 ` -PeerIPAddress 14.1.1.10 -PeerASN 64512 ` -OperationMode Server -PeeringMode Manual -PassThruPeerName LocalIPAddress PeerIPAddress PeerASN OperationMode ConnectivityStatus-------- -------------- ------------- ------- ------------- ------------------RedTenantSite1 192.168.1.10 14.1.1.10 64512 Server Stopped255.4 Add-BgpCustomRoute, Add-BgpRouteAggregate, routing policies
| Cmdlet | Purpose | Key options |
|---|---|---|
| Add-BgpCustomRoute | Add own routes to the BGP table | -Interface (its unicast routes), -Network "172.23.90.0/29" |
| Add-BgpRouteAggregate | Summarize small routes into one bigger prefix | -Prefix, -SummaryOnly Enabled (peers get only the aggregate), -PreserveASPath, -AttributePolicy |
| Add-BgpRoutingPolicy | Filter or change routes | -PolicyType Deny|Allow|ModifyAttribute; Match: -MatchPrefix, -MatchASNRange, -MatchCommunity; Set: -NewLocalPref, -NewMED, -NewNextHop |
| Add-BgpRoutingPolicyForPeer | Apply a policy to a peer | -PolicyName, -PeerName, -Direction Ingress|Egress (asks to restart the session) |
Add-BgpCustomRoute -Interface "Ethernet" -PassThruAdd-BgpCustomRoute -Network "172.23.90.0/29" -PassThru Add-BgpRouteAggregate -RoutingDomain "Contoso" -Prefix "172.168.0.0/16" ` -AttributePolicy "P_StaticAggAttrib" -PreserveASPath enable Add-BgpRoutingPolicy -Name "RTPolicy04" -PolicyType ModifyAttribute ` -MatchPrefix 10.1.4.0/24 -IgnorePrefix 10.1.4.16/28 -NewLocalPref 400Add-BgpRoutingPolicyForPeer -PolicyName "RTPolicy01" ` -Direction Ingress -PeerName "TenantSite01"PS C:\> Add-BgpCustomRoute -Interface "Ethernet" -PassThruInterface : {Ethernet}Network :PS C:\> Add-BgpCustomRoute -Network "172.23.90.0/29" -PassThruInterface : {Ethernet}Network : {172.23.90.0/29}PS C:\> Add-BgpRoutingPolicyForPeer -PolicyName "RTPolicy01" -Direction Ingress -PeerName "TenantSite01"ConfirmBGP peering session could currently be active for TenantSite01. Do you want to apply these policies and restartcorresponding peering sessions?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y255.5 DirectAccess Add- cmdlets
- Step 1
1.Laptop outside the office (DA client) auto-connects via an IP-HTTPS tunnel to Entry Point 2
- Step 2
2.A contoso.com name query goes to the corporate DNS via the NRPT
- Step 3
3.Laptop reaches the app server (da-test-0807)
- Step 4
4.Mgmt server patch1.corp.contoso.com reaches the laptop for patching
- Step 5
5.Works even when no user is logged in
| Cmdlet | What it adds |
|---|---|
| Add-DAAppServer | Security group of application servers (+ an app server GPO) |
| Add-DAClient | Security groups of client computers; -Downlevel* for older clients |
| Add-DAClientDnsConfiguration | DNS suffix + DNS server into the NRPT (-ProxyServer for web traffic) |
| Add-DAEntryPoint | New entry point in multi-site: -Name, -RemoteAccessServer, -ConnectToAddress (public name), -InternalInterface, -InternetInterface, -GslbIP, -DeployNat |
| Add-DAMgmtServer | Management servers like a patch server |
Add-DAAppServer -SecurityGroupNameList daAppServerGrp -PassThruAdd-DAClient -SecurityGroupNameList 'corp.contoso.com\DirectAccessLaptopClients'Add-DAClientDNSConfiguration -DnsSuffix contoso.com ` -DnsIPAddress 2006:2005:1::2 -PassThru Add-DAEntryPoint -Name "Entry Point 2" ` -RemoteAccessServer "da2.domain1.corp.contoso.com" ` -ConnectToAddress "ep2.da.contoso.com" ` -InternalInterface CorpNet1 -InternetInterface Internet ` -ClientIPv6Prefix 3000:0:30:2000::/64 -GslbIP "137.5.0.50"Add-DAMgmtServer -MgmtServer patch1.corp.contoso.comPS C:\> Add-DAClientDNSConfiguration -DnsSuffix contoso.com -DnsIPAddress 2006:2005:1::2 -PassThruDirectAccessDnsServers : {2006:2005:1::2}DirectAccessEnabled : TrueDirectAccessProxyType : DirectName : DA-{64329e4f-bd27-4d27-9553-6ed6880fa2a5}Namespace : {contoso.com} Entry Point 2 137.5.0.50 {da2.domain1.corp.contoso.com}PS C:\>Get-DAMultiSiteEnterpriseName : Company EnterpriseManualSiteSelectionAllowed : EnabledDAEntryPoints : {Entry Point 1, Entry Point 2}255.6 RADIUS, IP filter, load balancer node, VPN pool
- Add-RemoteAccessRadius: -ServerName, -SharedSecret, -Purpose Authentication|Accounting|Otp; -Score default 30, -Timeout default 5 s.
- Ports in the docs output: authentication 1812, accounting 1813.
- Add-VpnIPAddressRange: IPv4 pool for VPN clients, e.g. 40.1.1.10 to 40.1.1.30.
- Add-RemoteAccessIpFilter: -InterfaceAlias, -Action, -Direction, -List "src:dst:protocol:data1:data2".
- Add-RemoteAccessLoadBalancerNode: adds a server to an existing NLB cluster; -VpnIPAddressRange gives the new node a pool when VPN is on.
Add-RemoteAccessRadius -ServerName 10.1.2.1 Authentication "s3cr3t2" -PassThruAdd-RemoteAccessRadius -ServerName 10.1.3.1 Accounting "s3cr3t5" -PassThruAdd-VpnIPAddressRange -IPAddressRange 40.1.1.10, 40.1.1.30 -PassThru Add-RemoteAccessIpFilter -InterfaceAlias Interface01 -Action Allow ` -Direction Outbound -AddressFamily IPv4 -Passthru ` -List @("10.0.0.0/16:10.2.0.0/16:TCP:1234:4321") $RemoteAccessNLB = Add-RemoteAccessLoadBalancerNode ` -RemoteAccessServer Edge2.corp.contoso.com -PassThru$RemoteAccessNLB.NlbNodeStatusServerName Purpose Score Timeout(s) Port AccountingOnOffMsg MsgAuthenticator---------- ------- ----- ---------- ---- ------------------ ----------------10.1.2.1 Authentication 30 5 1812 DisabledServerName Purpose Score Timeout(s) Port AccountingOnOffMsg MsgAuthenticator---------- ------- ----- ---------- ---- ------------------ ----------------10.1.3.1 Accounting 30 5 1813 Disabled WARNING: When adding a server (running the network location server using a self-signed certificate) to a cluster, point the network location server DNS entry to the internal DIP of each cluster server.PS C:\>$RemoteAccessNLB.NlbNodeStatus{EDGE1.CORP.CONTOSO.COM, EDGE2.CORP.CONTOSO.COM}255.7 Lab: BGP with FRRouting
- Linux equivalent: n255-bgp 192.168.155.0/24, router1 .11 AS 65001, router2 .12 AS 65002, Alpine + FRRouting 10.0.
- router bgp 65001 = Add-BgpRouter; neighbor ... remote-as = Add-BgpPeer; network = Add-BgpCustomRoute; aggregate-address = Add-BgpRouteAggregate; route-map out = Add-BgpRoutingPolicyForPeer (Egress).
- FRR follows RFC 8212: on eBGP nothing is sent/received without a policy, so the summary shows (Policy). The lab turned this off with no bgp ebgp-requires-policy.
- BGP runs in userspace on TCP 179: the 22 kernel modules stayed the same.
vtysh -c 'conf t' -c 'router bgp 65001' \ -c 'bgp router-id 192.168.155.11' \ -c 'neighbor 192.168.155.12 remote-as 65002' \ -c 'neighbor 192.168.155.12 description router2'vtysh -c 'show bgp summary'netstat -tn | grep ':179'192.168.155.12 4 65002 3 3 0 0 0 00:00:12 (Policy) (Policy) router2[router1]$ netstat -tn | grep ':179'tcp 0 0 192.168.155.11:179 192.168.155.12:60014 ESTABLISHEDvtysh -c 'conf t' -c 'router bgp 65001' -c 'no bgp ebgp-requires-policy'ip addr add 10.255.1.1/24 dev loip addr add 10.255.2.1/24 dev loip addr add 10.255.3.1/24 dev lovtysh -c 'conf t' -c 'router bgp 65001' -c 'address-family ipv4 unicast' \ -c 'network 10.255.1.0/24' -c 'network 10.255.2.0/24' -c 'network 10.255.3.0/24' \ -c 'aggregate-address 10.255.0.0/22'vtysh -c 'show ip bgp neighbors 192.168.155.12 advertised-routes'ip -4 route # on router2[router1]$ vtysh -c 'show ip bgp neighbors 192.168.155.12 advertised-routes' Network Next Hop Metric LocPrf Weight Path *> 10.255.0.0/22 0.0.0.0 0 32768 i *> 10.255.1.0/24 0.0.0.0 0 32768 i *> 10.255.2.0/24 0.0.0.0 0 32768 i *> 10.255.3.0/24 0.0.0.0 0 32768 iTotal number of prefixes 4[router2]$ ip -4 route10.255.1.0/24 nhid 4 via 192.168.155.11 dev eth1 proto bgp metric 2010.255.2.0/24 nhid 4 via 192.168.155.11 dev eth1 proto bgp metric 2010.255.3.0/24 nhid 4 via 192.168.155.11 dev eth1 proto bgp metric 20192.168.155.0/24 dev eth1 proto kernel scope link src 192.168.155.12vtysh -c 'conf t' \ -c 'ip prefix-list LAB3 seq 5 permit 10.255.3.0/24' \ -c 'route-map TO-R2 deny 10' \ -c 'match ip address prefix-list LAB3' -c 'exit' \ -c 'route-map TO-R2 permit 20' \ -c 'set metric 400' -c 'exit' \ -c 'router bgp 65001' \ -c 'address-family ipv4 unicast' \ -c 'neighbor 192.168.155.12 route-map TO-R2 out'vtysh -c 'clear bgp ipv4 unicast 192.168.155.12 soft out'vtysh -c 'show bgp summary'[router1]$ vtysh -c 'show bgp summary'Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc192.168.155.12 4 65002 8 12 4 0 0 00:00:58 0 3 router2- After the policy: 10.255.3.0/24 is denied, the other 3 prefixes go out with metric 400 (PfxSnt 3).
255.8 Common mistakes
- Thinking "peer up = routes flowing": the lab session was ESTABLISHED but PfxRcd/PfxSnt showed (Policy) and 0 routes; always check prefix counts and advertised-routes.
- Forgetting that Add-BgpRoutingPolicyForPeer restarts the peering session.
- Mixing up RADIUS ports: 1812 authentication, 1813 accounting.
- Adding an aggregate without -SummaryOnly and expecting peers to get only the summary.
255.9 Interview tips
- Advertise only one prefix to a peer: Add-BgpRoutingPolicy -MatchPrefix ... then Add-BgpRoutingPolicyForPeer -Direction Egress.
- VPN vs DirectAccess: VPN = user connects, pool IP, RADIUS login; DirectAccess = always-on for domain-joined clients via GPO, NRPT, IP-HTTPS, manageable before logon.
- BGP uses TCP 179; states go Connecting -> OPEN -> Established.
- Mention RFC 8212 (eBGP needs a policy) when explaining why no routes are exchanged.