param(
    $sPublicAdapterName,
    $sPrivateAdapterName
)

if (!$sPrivateAdapterName) {
	# See https://social.technet.microsoft.com/Forums/windowsserver/en-US/bb2235c9-3961-4394-b0ab-9fcccd50248a/passing-command-line-args-with-quotes?forum=winserverpowershell
    Write-Host "IdentifyNetworkCardsAndEnableICS.ps1 sPublicAdapterName sPrivateAdapterName"
    return
}

$netShare = New-Object -ComObject HNetCfg.HNetShare
$netShare.EnumEveryConnection |% { $netShare.NetConnectionProps.Invoke($_) }
$netConnectionPublic = $netShare.EnumEveryConnection |? { $netShare.NetConnectionProps.Invoke($_).Name -eq $sPublicAdapterName }

$netConnectionPrivate = $netShare.EnumEveryConnection |? { $netShare.NetConnectionProps.Invoke($_).Name -eq $sPrivateAdapterName }
$config1 = $netShare.INetSharingConfigurationForINetConnection.Invoke($netConnectionPublic)
$config2 = $netShare.INetSharingConfigurationForINetConnection.Invoke($netConnectionPrivate)
$config1.DisableSharing()
$config2.DisableSharing()
$config1.EnableSharing(0)
$config2.EnableSharing(1)
