-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSET_DNS_IP.ps1
87 lines (58 loc) · 2.6 KB
/
SET_DNS_IP.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<#
.SYNOPSIS
Think powershell think like Mr-ITpro.com !!! FUN STUFF
.EXAMPLE
'one', 'two', 'three' TonyB_default.ps1
.EXAMPLE
TonyB_default.ps1 $Divcodes
.EXAMPLE
TonyB_default.ps1 one, two, three
.EXAMPLE
get-content <Somelist.txt> or <anylist.csv> | SET_DNS_IPs.ps1
.PARAMETER computername
one or more computername, or IP address... peace to America!
.LINK
http://www.mr-itpro.com
#>
[CmdletBinding(HelpURI='http://google.com')]
Param(
[Parameter(Mandatory=$true,ValuefromPipeline=$true)]
[string []]$Servers,
[string]$errorlogpath ='c:\temp\DNS_IP_error_.log'
)
begin{
$host.UI.RawUI.WindowTitle = "Change DNS IP address."
Write-Host " "
import-Module ActiveDirectory
$starttime =Get-Date
$dnsserver1 = "192.168.1.1"
$dnsserver2 = Read-Host "enter dns server 2"
}
process{
foreach($Server in $Servers) {
Write-Verbose "about to query $Servers"
try {
$serverislive =$true
$who = Get-WMIObject Win32_ComputerSystem -computername $Server | Select-Object -ExpandProperty name
} catch {
$serverislive = $false
Write-Verbose "$Server can not be reached.Please check firewall, network , or related issues. "
Write-Verbose " Error was $MyErr"
$Server | Out-File $errorlogpath -append
}
}
$strSearchOrderLocation = "$dnsserver1", "$dnsserver2"
$Server
#$Server = get-adcomputer -filter {name -like "*"} -searchbase "ou=servers,ou=location,dc=company,dc=com"
foreach ($Server in $Servers){
$config = Get-WmiObject -ComputerName $Server -class win32_networkadapterconfiguration | Where-Object { ($_.IPAddress -ne $null) }
$config.SetDNSServerSearchOrder($strSearchOrderLocation)
Write-Host $Server
resolve-dnsname $Server
}
}
End{
$endtime =Get-Date
$total= $endtime -$starttime
Write-host "Total Script time to run $total" -ForegroundColor Yellow | ft -AutoSize
}