-
Notifications
You must be signed in to change notification settings - Fork 4
/
iLO_HostNameUpdate.ps1
64 lines (49 loc) · 1.93 KB
/
iLO_HostNameUpdate.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
<#
Name: iLO_HostNameUpdate.ps1
Purpose: This script is used to modify the iLO Hostname.
This is done by:
Finding available iLOs within the given range
Checking if there's a valid DNS entry
Checking if the credentials given are valid
Checking if the iLO hostname hasn't already been set
Setting the iLO hostname
Execution: ./iLO_HostNameUpdate.ps1
Creator: Kyle Ruddy
#>
#Gathering IP Address range
$Range = Read-Host "`nWhat IP address or range should have their iLO hostname updated?"
#Gathering all possible iLOs
$FoundiLO = Find-HPiLO $Range -ErrorAction silentlycontinue -WarningAction silentlycontinue
Write-Host ""
#Verify iLOs were indeed found
if ($FoundiLO -eq $null) {
Write-Host "No iLOs found for that entry.`n"
Exit
}
#Gather the credentials required to authenticate to the iLO system
$creds = Get-Credential -Message "Please enter the credentials required for the iLO/s."
#Loop through the found iLOs
foreach ($ilo in $FoundiLO) {
$currIP = $ilo.IP
#Verify a DNS entry exists for the current iLO IP
$dnsCheck = Resolve-DNSName $currIP -erroraction silentlycontinue
if ($dnsCheck -eq $null) {Write-Host "$currIP - No DNS entry found for iLO at this IP"}
else {
#Verify iLO status
$currState = Get-HPiLONetworkSetting -Server $currIP -Credential $creds -WarningAction silentlycontinue
if ($currState.Status_Type -eq "ERROR") {Write-Host "$currIP - iLO shows a current status of"$currState.Status_Message}
else{
#Verify what the current iLO Hostname is
$currName = $currState.DNS_Name
#Gather proper formatting of DNS check output
$dnsName = ($dnsCheck.NameHost).Split('.')[0]
if ($currName -notlike $dnsName) {
#Updating iLO Hostname to match DNS name
Set-HPiLONetworkSetting -Server $currIP -DNSName $dnsName -Credential $creds
Write-Host "$currIP - Updated from current name of $currName to $dnsName"
}
if ($currName -like $dnsName) {Write-Host "$currIP - Current name already matches the iLO Hostname"}
}
}
}
Write-Host ""