PowerShell script that enables Internet Connection Sharing (ICS)

1 minute reading time (194 words)
wholemilkers_share_iconnection_with_multiple_computers__a11660e6-618b-47fd-b0e3-784e0df949b8

Here's an example PowerShell script that enables Internet Connection Sharing (ICS) for multiple machines:

# Define the host machine's network adapter
$hostAdapter = "Ethernet 2"
# Define the client machines' network adapters
$clientAdapters = @("Ethernet", "Ethernet 2", "WiFi")

# Enable ICS on the host machine
New-NetSharingConfiguration -SharingEnabled $true -Name "Internet Connection" -AdapterName $hostAdapter

# Configure the firewall on the host machine to allow ICS traffic
Set-NetFirewallRule -DisplayGroup "Network Discovery" -Enabled True
Set-NetFirewallRule -DisplayGroup "File and Printer Sharing" -Enabled True
Set-NetFirewallRule -DisplayGroup "Remote Desktop" -Enabled True

# Enable ICS on each client machine
foreach ($adapter in $clientAdapters) {
    $client = Test-Connection -ComputerName $adapter -Count 1 -Quiet
    if ($client -eq $true) {
        Invoke-Command -ComputerName $adapter -ScriptBlock {
            New-NetSharingConfiguration -SharingEnabled $true -Name "Internet Connection"
        }
    }
} 

This script first defines the host machine's network adapter and the network adapters of the client machines. It then enables ICS on the host machine using the New-NetSharingConfiguration cmdlet. The script also configures the firewall on the host machine to allow ICS traffic.

Finally, the script loops through the client machines' network adapters and enables ICS on each machine using the Invoke-Command cmdlet. This allows the client machines to access the internet through the host machine's network connection. 


Font size: +
Report Print
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

By accepting you will be accessing a service provided by a third-party external to https://www.klokur.com/