# The name for the loopback adapter interface that will be created. $loopback_name = "LoopbackAAA$val"
New-LoopbackAdapter -Name $loopback_name -Force
# Commented this line out but you're probably gonna want it so you don't end up like me #Get-NetAdapter $loopback_name | Set-DNSClient –RegisterThisConnectionsAddress $False
Write-Host $val } New-LoopbackAdapter -Name test -Force
.DESCRIPTION Installs Chocolatey from the internet if it is not installed, then uses it to download the DevCon.Portable (Windows Device Console) package. The devcon.portable Chocolatey package can be found here and installed manually if no internet connection is available: https://chocolatey.org/packages/devcon.portable/
Chocolatey will remain installed after this function is called.
.PARAMETER Force Force the install of Chocolatey and the Devcon.portable package if not already installed, without confirming with the user.
.EXAMPLE Install-Devcon
.OUTPUTS The fileinfo object containing the appropriate DevCon*.exe application that was installed for this architecture. #> function Install-Devcon { [OutputType([System.IO.FileInfo])] [CmdLetBinding( SupportsShouldProcess = $true, ConfirmImpact = 'High')] param ( [Parameter()] [Switch] $Force )
Install-Chocolatey @PSBoundParameters
# Check DevCon installed - if not, install it. $devConInstalled = ((Test-Path -Path "$ENV:ProgramData\Chocolatey\Lib\devcon.portable\Devcon32.exe") ` -and (Test-Path -Path "$ENV:ProgramData\Chocolatey\Lib\devcon.portable\Devcon64.exe"))
if (-not $devConInstalled) { try { <# This will download and install DevCon.exe It will also be automatically placed into the path #> if ($Force -or $PSCmdlet.ShouldProcess($LocalizedData.DownloadAndInstallDevConShould)) { Write-Verbose -Message $LocalizedData.InstallDevconMessage $null = & choco @('install','-r','-y','devcon.portable') } else { throw $LocalizedData.DevConNotInstalledError } } catch { throw ($LocalizedData.DevConInstallationError -f $_) } }
.DESCRIPTION Installs Chocolatey from the internet if it is not installed, then uses it to uninstall the DevCon.Portable (Windows Device Console) package.
Chocolatey will remain installed after this function is called.
.PARAMETER Force Force the uninstall of the devcon.portable package if it is installed, without confirming with the user.
try { <# This will download and install DevCon.exe It will also be automatically placed into the path #> if ($Force -or $PSCmdlet.ShouldProcess($LocalizedData.UninstallDevConShould)) { $null = & choco @('uninstall','-r','-y','devcon.portable') } else { throw $LocalizedData.DevConNotUninstalledError } } catch { throw ($LocalizedData.DevConNotUninstallationError -f $_) } } #EndRegion './Private/Uninstall-Devcon.ps1' 54 #Region './Private/Wait-ForDevconUpdate.ps1' 0 <# .SYNOPSIS Waits for changes made by DevCon.exe to complete before continuing.
.DESCRIPTION Waits for the DevCon.exe process to exit and then checks whether Get-NetAdapter completes successfully. Get-NetAdapter will throw "Illegal operation attempted on a registry key that has been marked for deletion." if the changes are still processing.
.PARAMETER DevconExeTimeout Time in seconds to wait for the DevCon process to complete.
.PARAMETER RegistryUpdateTimeout Time in seconds to wait for the registry to finish processing changes.
# Check for the existing Loopback Adapter $adapter = Get-NetAdapter ` -Name $Name ` -ErrorAction SilentlyContinue
# Is the loopback adapter installed? if ($adapter) { throw ($localizedData.NetworkAdapterExistsError -f $Name) } # if
# Make sure DevCon is installed. $devConExe = (Install-Devcon @PSBoundParameters).FullName
<# Get a list of existing Loopback adapters This will be used to figure out which adapter was just added #> $existingAdapters = (Get-LoopbackAdapter).PnPDeviceID
<# Use Devcon.exe to install the Microsoft Loopback adapter Requires local Admin privs. #> Write-Verbose -Message ($LocalizedData.CreatingLoopbackAdapterMessage -f $Name) $null = & $DevConExe @('install', "$($ENV:SystemRoot)\inf\netloop.inf", '*MSLOOP') Wait-ForDevconUpdate
if (-not $adapter) { throw ($LocalizedData.NewNetworkAdapterNotFoundError -f $Name)# The new Loopback Adapter '{0}' was not found. } # if
# Rename the new Loopback adapter Setting the name of the new Loopback Adapter to '{0}'. #Write-Verbose -Message ($adapter.Name) Write-Verbose -Message ($LocalizedData.SettingNameOfNewLoopbackAdapterMessage -f $Name) $null = Rename-NetAdapter ` -Name $adapter.Name ` -NewName $Name ` -ErrorAction Stop
# Set the metric to 254 Write-Verbose -Message ($LocalizedData.SettingMetricOfNewLoopbackAdapterMessage -f $Name) $null = Set-NetIPInterface ` -InterfaceAlias $Name ` -InterfaceMetric 254 ` -ErrorAction Stop
<# Wait till IP address binding has registered in the CIM subsystem. if after 30 seconds it has not been registered then throw an exception. #> [System.Boolean] $adapterBindingReady = $false [System.DateTime] $startTime = Get-Date
process { $null = $PSBoundParameters.Remove('Name')
# Check for the existing Loopback Adapter $adapter = Get-NetAdapter ` -Name $Name ` -ErrorAction SilentlyContinue
# Is the loopback adapter installed? if (-not $adapter) { # Adapter doesn't exist throw ($LocalizedData.LoopbackAdapterNotFound -f $Name) }
# Is the adapter Loopback adapter? if ($adapter.DriverDescription -ne 'Microsoft KM-TEST Loopback Adapter') { # Not a loopback adapter - don't uninstall this! throw ($LocalizedData.NetworkAdapterWrongTypeError -f $Name) } # if
# Make sure DevCon is installed and return path to executable $devConExe = (Install-Devcon @PSBoundParameters).FullName
<# Use Devcon.exe to remove the Microsoft Loopback adapter using the PnPDeviceID. Requires local Admin privs. #> Write-Verbose -Message ($LocalizedData.RemovingLoopbackAdapterMessage -f $Name) $null = & $devConExe @('remove',"@$($adapter.PnPDeviceID)") Wait-ForDevconUpdate } } # function Remove-LoopbackAdapter #EndRegion './Public/Remove-LoopbackAdapter.ps1' 49 #Region './suffix.ps1' 0 #EndRegion './suffix.ps1' 1