Tuesday, December 12, 2017

update DNS on all dell iDRAC servers

We had to automate the updation of DNS servers on all of our Dell iDRACs on VxRack. Here is a script which will help you if you ever face a similar situation.

 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
<#
.SYNOPSIS
    set DNS on dell iDRAC servers
.DESCRIPTION
    opens up a csv file. put the ip addresses of idrac, root username, password, dns1, dns2
.NOTES
    File Name      : idracSetDns.ps1
    Author         : gajendra d ambi
    Date           : Dec 2017
    Prerequisite   : PowerShell v4+, Dell OpenManage DRAC Tools, includes Racadm (64bit) v8.1 or higher
    Copyright      - None
.LINK
    Script posted over: github.com/MrAmbiG/
#>

#Start of Script
Write-Host "
A CSV file will be opened (open in excel/spreadsheet)
populate the values,
save & close the file,
Hit Enter to proceed
" -ForegroundColor Blue -BackgroundColor White

$csv = "$PSScriptRoot/idracSetDns.csv"
get-process | Select-Object idrac_ip_address, root_password, dns1, dns2| Export-Csv -Path $csv -Encoding ASCII -NoTypeInformation
Start-Process $csv
Read-Host "Hit Enter/Return to proceed"
Write-Host "processing your entries from the csv file...."
$csv = Import-Csv $csv
foreach ($line in $csv) 
 {
    $idrac_ip_address = $($line.idrac_ip_address)
    $root_password = $($line.root_password)
    $dns1 = $($line.dns1)
    $dns2 = $($line.dns2)
    $user = 'root'

    Write-Host "setting on $idrac_ip_address"
    # setting dhcp to 0 and dns1
    if ($dns1.Length -gt 2) {
    Write-Host Disabling dhcp dns on $server -ForegroundColor Yellow
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn config -g cfgLanNetworking -o cfgDNSDomainNameFromDHCP 0
    Write-Host setting dns server1 $dns1 -ForegroundColor Green
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn config -g cfgLanNetworking -o cfgDNSServer1 $dns1
    }

    # setting dns2
    if ($dns2.Length -gt 2) {
    Write-Host setting dns server1 $dns2 -ForegroundColor Green
    racadm -r $idrac_ip_address -u $user -p $root_password --nocertwarn config -g cfgLanNetworking -o cfgDNSServer2 $dns2
    }
 }