#Requires -Version 3.0
function Get-ICS {
	[CmdletBinding()]
	param (
		[Parameter(Mandatory,
				ValueFromPipeline,
				ValueFromPipelineByPropertyName)]
		[Alias('Name')]
		[string[]]$InternetInterfaceName
	)

	BEGIN {
		regsvr32.exe /s hnetcfg.dll
		$netShare = New-Object -ComObject HNetCfg.HNetShare
	}

	PROCESS {
		foreach ($Interface in $InternetInterfaceName){
		
			$publicConnection = $netShare.EnumEveryConnection |
			Where-Object {
				$netShare.NetConnectionProps.Invoke($_).Name -eq $Interface
			}
			
			try {
				$Results = $netShare.INetSharingConfigurationForINetConnection.Invoke($publicConnection)
			}
			catch {
				Write-Warning -Message "An unexpected error has occurred for network adapter: '$Interface'"
				Continue
			}

			[pscustomobject]@{
				Name = $Interface
				SharingEnabled = $Results.SharingEnabled
				SharingConnectionType = $Results.SharingConnectionType
				InternetFirewallEnabled = $Results.InternetFirewallEnabled
			}
			
		}
	
	}
}