Advertisement
Combreal

getRideOfWin7DHCP.ps1

Feb 25th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $exitFile = [string]::Empty
  2. $dhcpFile = [IO.File]::OpenText('C:\Temp\dhcpd.define')
  3. while ($dhcpFile.Peek() -ge 0) {
  4.     $dhcpLine = $dhcpFile.ReadLine()
  5.  
  6.     $namesFile = [IO.File]::OpenText('C:\Temp\hosts-glpi-win7-names-sorted.txt')
  7.     while ($namesFile.Peek() -ge 0) {
  8.            $namesLine = $namesFile.ReadLine()
  9.  
  10.            if($dhcpLine -Match " " + $namesLine + " ") {
  11.                 if($dhcpLine[0] -ne '#') {
  12.                     $dhcpLine = $dhcpLine.Insert(0, '#')
  13.                 }
  14.            }
  15.            ElseIf($dhcpLine -Match " " + $namesLine + "$") {
  16.             if($dhcpLine[0] -ne '#') {
  17.                 $dhcpLine = $dhcpLine.Insert(0, '#')
  18.             }
  19.        }
  20.     }
  21.     $namesFile.Dispose()
  22.     $exitFile = $exitFile + "`n" + $dhcpLine
  23. }
  24. $dhcpFile.Dispose()
  25. $exitFile | Out-File 'C:\Temp\exitDCHP.txt'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement