別のPowerShellソリューション:https : //gallery.technet.microsoft.com/scriptcenter/WLAN-Manager-f438a4d7
WLAN Managerはスケジュールされたタスクとして実行され、LAN接続が確認されるとWLANカードを自動的に無効にします。LAN接続が失われると、WLANカードは再び有効になります。これにより、利用可能な最速の接続が確保され、ネットワークブリッジの防止に役立ちます。
Microsoft Technetの「substance」による元のコード。ZIPファイル
################
# WLAN Manager #
################
#Version: 2015-03-03.2
#Author: johan.carlsson@innovatum.se
<#
.SYNOPSIS
Disables the WLAN NIC when LAN NIC network connection is verified.
Enables WLAN NIC when LAN NIC network connection is lost.
.DESCRIPTION
WLAN Manager runs as a scheduled task and will automatically disable your WLAN card when a LAN connection is verified.
The WLAN card will be re-enabled once the LAN connection is lost. This ensures you'll always have the fastest available connection and stops network bridging.
.EXAMPLE
.\WLANManager.ps1 -Install:$true
Installs WLAN Manager.
.EXAMPLE
.\WLANManager.ps1 -Remove:$true
Removes WLAN Manager.
.EXAMPLE
.\WLANManager.ps1
Verify Installaton > Install if missing > Run Interactively (first run only, hidden run via scheduled task run after that).
.EXAMPLE
.\WLANManager.ps1 -Interactive:$true
Runs WLAN Manager in an interactive window. Will not install anything. This mode is only for testing and watching what happens via console output.
.NOTES
None.
.LINK
https://support.innovatum.se
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$False,Position=1,HelpMessage="Installs WLAN Manager.")]
[switch]$Install,
[Parameter(Mandatory=$False,Position=2,HelpMessage="Removes WLAN Manager.")]
[switch]$Remove,
[Parameter(Mandatory=$False,Position=3,HelpMessage="Runs WLAN Manager interactively, doesn't install anything.")]
[switch]$Interactive
)
#########################################
# Custom Variables for Your Environment #
#########################################
#Destination Path to where you want to store files for local install of WLANManager
$CustomDestinationPath = "$env:ProgramFiles\WLANManager"
<#
D O N O T C H A N G E A N Y T H I N G B E L O W T H I S L I N E
#>
#################################
# Unload/Load PowerShell Module #
#################################
#Remove PowerShell Module
If ((Get-Module PSModule-WLANManager) -ne $null)
{
Remove-Module PSModule-WLANManager -Verbose
}
#Import PowerShell Module
$strBasePath = Split-Path -Path $MyInvocation.InvocationName
Import-Module "$strBasePath\PSModule-WLANManager.psm1" -Verbose
#############################
# Install or Update Install #
#############################
If ($Remove -eq $true)
{
Remove-WLANManager -FilePath $CustomDestinationPath
return
}
ElseIf ((Test-Path -Path $strBasePath) -eq $True -and ($Interactive) -ne $true)
{
#Install
Install-WLANManager -SourcePath $strBasePath -DestinationPath $CustomDestinationPath
If ($Install -eq $true)
{
#≥Windows 8
If ($OSInfo.Caption -match "Windows 8")
{
Start-ScheduledTask -TaskName "WLAN Manager"
Exit
}
#<Windows 8
Else
{
Start-STask -TaskName "WLAN Manager" | Out-Null
Exit
}
}
}
########
# Main #
########
while ($true)
{
If ((Test-WiredConnection) -eq $true -and (Test-WirelessConnection) -eq $true)
{
Write-Host "Wired connection detected, disabling Wireless connection... " -NoNewline -ForegroundColor Yellow
#≥Windows 8
If ($OSInfo.Caption -match "Windows 8")
{
Disable-NetAdapter -InterfaceDescription *Wireless* -Confirm:$false
}
#<Windows 8
Else
{
Disable-WLANAdapter | Out-Null
}
Write-Host "Done" -ForegroundColor White -BackgroundColor Green
}
If ((Test-WiredConnection) -eq $false -and (Test-WirelessConnection) -eq $false)
{
Write-Host "Wired connection lost, enabling Wireless connection... " -NoNewline -ForegroundColor Yellow
#≥Windows 8
If ($OSInfo.Caption -match "Windows 8")
{
Enable-NetAdapter -InterfaceDescription *Wireless* -Confirm:$false
}
#<Windows 8
Else
{
Enable-WLANAdapter | Out-Null
}
#Wait for WLAN Adapter to initialize and obtain an IP-address
while ((Test-WiredConnection) -eq $false -and (Test-WirelessConnection) -eq $false)
{
sleep -Seconds 1
}
Write-Host "Done" -ForegroundColor White -BackgroundColor Green
}
Else
{
Write-Host "Sleeping..." -ForegroundColor Yellow
sleep -Seconds 1
}
}