Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $remote = 0
- $computer = "localhost"
- if($remote -eq 1){
- $cred = Get-Credential #Domain\User
- Enter-PSSession $computer -Credential $cred
- }
- Push-Location
- #Settings
- $pInfo = "mydomain.com"
- $pCheck = "Domain" # could change this to DefaultGateway
- #Script
- $outer = ""
- $gotit = 0
- Set-Location hklm:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces
- Get-ChildItem '.\' | foreach {
- $inter = $_.Name.Split("\")[-1]
- cd $inter
- $varCheck = (Get-ItemProperty ".\" -Name $pCheck).$pCheck
- cd ..
- if ($varCheck -eq $pInfo) {
- $outer = $inter
- $gotit = 1
- }
- }
- #Check if we got our interface, if not then we quit.
- if ($gotit -eq 0) {
- write-host "Well shit.. We didn't find $pInfo."
- Exit
- }
- #---------result = $outer
- Set-Location hklm:\System\CurrentControlSet\Services\Tcpip\Linkage\
- #----Bind
- $curBindOrder = (Get-ItemProperty '.\' -Name Bind).Bind
- $order = $curBindOrder
- $topItem = “\Device\$outer”
- $strNewProvs = $topItem
- $i = 1
- $order -Split([environment]::NewLine) | ForEach {
- if($i -eq 1){
- if($_ -eq $topItem){
- Write-Host "Exiting: $_ is at the top"
- Pop-Location
- Exit
- }
- }
- if($_ -ne $topItem){
- $i= $i + 1
- $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
- }
- $newBindOrder = $strNewProvs
- #----Export
- $curExportOrder = (Get-ItemProperty '.\' -Name Export).Export
- $order = $curExportOrder
- $topItem = “\Device\Tcpip_$outer”
- $strNewProvs = $topItem
- $i = 1
- $order -Split([environment]::NewLine) | ForEach {
- if($i -eq 1){
- if($_ -eq $topItem){
- Write-Host "Exiting: $_ is at the top"
- Pop-Location
- Exit
- }
- }
- if($_ -ne $topItem){
- $i= $i + 1
- $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
- }
- $newExportOrder = $strNewProvs
- #----Route
- $curRouteOrder = (Get-ItemProperty '.\' -Name Route).Route
- $order = $curRouteOrder
- $topItem = '"' + $outer + '"'
- $strNewProvs = $topItem
- $i = 1
- $newline = '"' + [environment]::NewLine + '"'
- $order -Split($newline) | ForEach {
- if($i -eq 1){
- if($_ -eq $topItem){
- Write-Host "Exiting: $_ is at the top"
- Pop-Location
- Exit
- }
- }
- if($_ -ne $topItem){
- write-host $topItem
- $i= $i + 1
- $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
- }
- $newRouteOrder = $strNewProvs
- Write-Host $newBindOrder
- Write-Host $newExportOrder
- Write-Host $newRouteOrder
- Set-ItemProperty '.\' -Name Bind -Value $newBindOrder
- Set-ItemProperty '.\' -Name Export -Value $newExportOrder
- Set-ItemProperty '.\' -Name Route -Value $newRouteOrder
- if($remote -eq 1){
- Exit-PSSession
- }
- Pop-Location
Advertisement
Add Comment
Please, Sign In to add comment