Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Start WLANAutoConfig Service
- $WLANAutoConfig = Get-Service -Name "WlanSvc"
- if ($WLANAutoConfig.Status -ne 'Running')
- {
- Write-Verbose "Starting WlanSvc"
- Start-Service -Name "WlanSvc"
- $WLANAutoConfig.WaitForStatus('Running','00:00:05')
- }
- #endregion Start WLANAutoConfig Service
- #region Remove existing hostednetwork configuration
- $HostedNetworkSettings = "HKLM:\SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\HostedNetworkSettings"
- If ((Test-Path $HostedNetworkSettings) -eq $true)
- {
- Write-Verbose "Removing Hosted Network"
- netsh wlan stop hostednetwork | out-null
- netsh wlan set hostednetwork mode=disallow | out-null
- Remove-Item "HKLM:\SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\HostedNetworkSettings" -Force
- }
- #endregion Remove Existing Hosted Network Configuration
- #region Set & Start Hotspot
- netsh wlan set hostednetwork mode=allow ssid=Hotspot key=H0tspot1 | out-null
- netsh wlan start hostednetwork | out-null
- #endregion Set & Start Hotspot
- #region Internet Connection Sharing
- # The Adapter you use to connect to the internet
- $PublicAdapterName = (Get-NetAdapter | Where-Object {$_.MediaConnectionState -eq 'Connected' -and $_.PhysicalMediaType -ne 'Unspecified'} | Sort-Object LinkSpeed | select -First 1).name
- # Your Hotspot
- $PrivateAdapterName = (Get-NetAdapter | Where-Object {$_.Virtual -eq $true -and $_.MediaConnectionState -eq 'Connected' -and $_.InterfaceDescription -eq "Microsoft Hosted Network Virtual Adapter"} | select -First 1).name
- function InternetConnectionSharing
- {
- [CmdletBinding()]
- param (
- [Parameter(Mandatory = $true)]
- $sPublicConnectionName,
- [Parameter(Mandatory = $true)]
- $ssPrivateConnectionName,
- [Parameter(Mandatory=$false)]
- [Switch]$bEnable
- )
- process
- {
- try
- {
- $oNetSharingManager = New-Object -ComObject HNetCfg.HNetShare
- }
- catch
- {
- regsvr32 /s hnetcfg.dll
- $oNetSharingManager = New-Object -ComObject HNetCfg.HNetShare
- }
- $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
- ForEach ($oItem in $oConnectionCollection)
- {
- $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
- $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
- if ($objNCProps.name -eq $ssPrivateConnectionName)
- {
- if ($bEnable)
- {
- $EveryConnection.EnableSharing(1)
- }
- else
- {
- $EveryConnection.DisableSharing()
- }
- }
- }
- $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
- ForEach ($oItem in $oConnectionCollection)
- {
- $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
- $objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
- if ($objNCProps.name -eq $sPublicConnectionName)
- {
- if ($bEnable)
- {
- $EveryConnection.EnableSharing(0)
- }
- else
- {
- $EveryConnection.DisableSharing()
- }
- }
- }
- }
- }
- InternetConnectionSharing -sPublicConnectionName $PublicAdapterName -ssPrivateConnectionName $PrivateAdapterName -bEnable
- #endregion Internet Connection Sharing
Advertisement
Add Comment
Please, Sign In to add comment