Guest User

Set-InterfaceOrder.ps1

a guest
Jul 25th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $remote = 0
  2. $computer = "localhost"
  3.  
  4. if($remote -eq 1){
  5.     $cred = Get-Credential #Domain\User
  6.     Enter-PSSession $computer -Credential $cred
  7. }
  8.  
  9. Push-Location
  10.  
  11. #Settings
  12. $pInfo = "mydomain.com"
  13. $pCheck = "Domain" # could change this to DefaultGateway
  14.  
  15. #Script
  16. $outer = ""
  17. $gotit = 0
  18. Set-Location hklm:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces
  19. Get-ChildItem '.\' | foreach {
  20.     $inter = $_.Name.Split("\")[-1]
  21.     cd $inter
  22.     $varCheck = (Get-ItemProperty ".\" -Name $pCheck).$pCheck
  23.     cd ..
  24.     if ($varCheck -eq $pInfo) {
  25.         $outer = $inter
  26.         $gotit = 1
  27.     }
  28. }
  29.  
  30. #Check if we got our interface, if not then we quit.
  31. if ($gotit -eq 0) {
  32.     write-host "Well shit.. We didn't find $pInfo."
  33.     Exit
  34. }
  35.  
  36. #---------result = $outer
  37.  
  38. Set-Location hklm:\System\CurrentControlSet\Services\Tcpip\Linkage\
  39.  
  40. #----Bind
  41. $curBindOrder = (Get-ItemProperty '.\' -Name Bind).Bind
  42. $order = $curBindOrder
  43. $topItem = “\Device\$outer
  44. $strNewProvs = $topItem
  45. $i = 1
  46.  
  47. $order -Split([environment]::NewLine) | ForEach {
  48.     if($i -eq 1){
  49.         if($_ -eq $topItem){
  50.             Write-Host "Exiting: $_ is at the top"
  51.             Pop-Location
  52.             Exit
  53.         }
  54.     }
  55.     if($_ -ne $topItem){
  56.         $i= $i + 1
  57.         $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
  58. }
  59. $newBindOrder = $strNewProvs
  60.  
  61. #----Export
  62. $curExportOrder = (Get-ItemProperty '.\' -Name Export).Export
  63. $order = $curExportOrder
  64. $topItem = “\Device\Tcpip_$outer
  65. $strNewProvs = $topItem
  66. $i = 1
  67.  
  68. $order -Split([environment]::NewLine) | ForEach {
  69.     if($i -eq 1){
  70.         if($_ -eq $topItem){
  71.             Write-Host "Exiting: $_ is at the top"
  72.             Pop-Location
  73.             Exit
  74.         }
  75.     }
  76.     if($_ -ne $topItem){
  77.         $i= $i + 1
  78.         $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
  79. }
  80. $newExportOrder = $strNewProvs
  81.  
  82. #----Route
  83. $curRouteOrder = (Get-ItemProperty '.\' -Name Route).Route
  84. $order = $curRouteOrder
  85. $topItem = '"' + $outer + '"'
  86. $strNewProvs = $topItem
  87. $i = 1
  88. $newline = '"' + [environment]::NewLine + '"'
  89. $order -Split($newline) | ForEach {
  90.     if($i -eq 1){
  91.         if($_ -eq $topItem){
  92.             Write-Host "Exiting: $_ is at the top"
  93.             Pop-Location
  94.             Exit
  95.         }
  96.     }
  97.     if($_ -ne $topItem){
  98.     write-host $topItem
  99.         $i= $i + 1
  100.         $strNewProvs = $strNewProvs + [environment]::NewLine + $_}
  101. }
  102. $newRouteOrder = $strNewProvs
  103.  
  104. Write-Host $newBindOrder
  105. Write-Host $newExportOrder
  106. Write-Host $newRouteOrder
  107.  
  108.  
  109.  
  110. Set-ItemProperty '.\' -Name Bind -Value $newBindOrder
  111. Set-ItemProperty '.\' -Name Export -Value $newExportOrder
  112. Set-ItemProperty '.\' -Name Route -Value $newRouteOrder
  113.  
  114.  
  115. if($remote -eq 1){
  116.     Exit-PSSession
  117. }
  118. Pop-Location
Advertisement
Add Comment
Please, Sign In to add comment