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.