##SetWifiDNS.ps1
##Gets the ip details of "wifi" net adapter, and if has 192.168.0, then it sets 192.168.0.2 to first DNS;
##otherwise will just reset the DNS!!
##Needs error handling
$currentDir = (Get-Item -Path ".\").FullName+"\"
$wifiPrivateSubnet = "192.168.0."
$wifiPrivateDNS = "192.168.0.2,1.1.1.1,1.0.0.1,8.8.8.8"
$wifiName = "wifi"
$wifiIp = Get-NetIPConfiguration -InterfaceAlias $wifiName | select IPv4Address, InterfaceAlias
# Details for logging
$LogPath = $currentDir
$LogFile = $LogPath+"SetWifiDNS.log"
$LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
Write-Host $wifiName $wifiIp.IPv4Address.IPAddress "is checking to match" $wifiPrivateSubnet
$matchesThePrivate = $wifiIp.IPv4Address.IPAddress -Match "192.168.0."
If ($matchesThePrivate) {
#if 192.168.0.2 network:
Get-NetAdapter -Name $wifiName | Set-DnsClientServerAddress -ServerAddresses $wifiPrivateDNS
$msg = $wifiName+" being set to DNS "+$wifiPrivateDNS
}
Else {
#otherwise
Get-NetAdapter -Name $wifiName | Set-DnsClientServerAddress -ResetServerAddresses
$msg = $LogTime+$wifiName+" being reset, logging to "+$LogFile
}
if(-Not [IO.Directory]::Exists($LogPath))
{
New-Item -ItemType directory -Path $LogPath
}
$LogTime+" - "+$msg | Out-File $LogFile -Append -Force