locked
Enabling ICS with Powershell RRS feed

  • Question

  • I tried the info on the following page:

    link left out as the system doesn't trust me just yet (Verification).

    social.technet.microsoft.com/Forums/lync/en-US/88003b3b-0e5c-49a7-bb20-cdbbbb435d09/enabling-windows-ics-from-powershell

    While it will set ICS sharing on the public adapter, it will not set the private IP address 192.168.137.1 on the private adapter.

    When doing this manually, it works perfectly. 

    When disabling ICS after setting it with the script, it also given an error that an element is missing.

    That makes me think that the script isn't fully activating ICS as seen in the failure in setting the private IP. 

    Wednesday, May 22, 2019 4:58 PM

All replies

  • I tried the script found here.

    I already tried the link below.

    http: //social.technet.microsoft.com/Forums/lync/en-US/88003b3b-0e5c-49a7-bb20-cdbbbb435d09/enabling-windows-ics-from-powershell

    While it does check the ICS shared connection box, the opposing Adapter doesn't get the 192.168.137.1 IP so it cannot function as the gateway.

    When I share the connection manually, it works perfectly.

    can anyone address this and how they may have fixed it?

    I have potentially a very large number of systems I need to configure with ICS and cannot possibly touch all of them without a centralized management method.

    Here's the script from the linked page.

    # Register the HNetCfg library (once)
    regsvr32 hnetcfg
    .dll

    $MainAdapter
    = Get-NetAdapter | Where-Object {$_.MediaConnectionState -eq 'Connected' -and $_.PhysicalMediaType -ne 'Unspecified'} | Sort-Object LinkSpeed -Descending

    function EnableICS([string]$ID)
    {
       
    # Create a NetSharingManager object
        $m
    = New-Object -ComObject HNetCfg.HNetShare

       
    # List connections
        $m
    .EnumEveryConnection |% { $m.NetConnectionProps.Invoke($_).Guid }

       
    # Find connection
        $c
    = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Guid -eq $ID }
       
       
    # Get sharing configuration
        $config
    = $m.INetSharingConfigurationForINetConnection.Invoke($c)
       
       
    # See if sharing is enabled
       
    Write-Output $config.SharingEnabled

       
    # See the role of connection in sharing
       
    # 0 - public, 1 - private
       
    # Only meaningful if SharingEnabled is True
       
    Write-Output $config.SharingType

       
    # Enable sharing (0 - public, 1 - private)
        $config
    .EnableSharing(0)
       
       
    # Disable sharing
       
    #$config.DisableSharing()
    }

    EnableICS($MainAdapter.InterfaceGuid)

    • Merged by Bill_Stewart Wednesday, May 22, 2019 10:49 PM Duplicate
    Wednesday, May 22, 2019 4:49 PM
  • This script is on the Microsoft TechNet page and is listed as closed but it doesn't work properly. 

    I've posted it to see if I can get a correction to a closed TechNet posted topic that doesn't work...

     


    • Edited by Tech Frog Wednesday, May 22, 2019 6:10 PM
    Wednesday, May 22, 2019 6:07 PM
  • This script is on the Microsoft TechNet page and is listed as closed but it doesn't work properly. 

    I've posted it to see if I can get a correction to a closed TechNet posted topic that doesn't work...

     


    We don't fix scripts you have found.  Yu can try to rewrite or fix the script yourself.  If you have a specific question then ask it.


    \_(ツ)_/

    Wednesday, May 22, 2019 9:54 PM