Instantly share code, notes, and snippets.

@jungopro jungopro/Readme.md
Last active Jan 11, 2018

Embed
What would you like to do?
Configure HP Bios Settings

SetBiosConfiguration.ps1 Usage and Description

Description

This script will take parameters from .CSV file and configure various BIOS options on HP DL360 / DL380 Server (Gen9)

Prerequisites

  • Windows Workstation with Powershell 5.1 installed
  • HP Powershell cmdlets for BIOS & iLO installed
  • You must configure iLO IP and all servers must have the same iLO Admin credentials
  • Servers must be turned off before running the script
  • Script must run with admin privileges

UEFI Boot Order Modifications:

The default boot order is to boot from RAID device and then 10GB Ethernet #1 Interface. This setup assumes RAID located in position #2 and 10GB Ethernet in location #3 in the current UEFI Boot Order. If you need to modify it, please run Get-Help Set-HPBIOSUEFIBootOrder - Detailed for cmdlet explanation and follow the steps there

Parameters

Servers_CSV

Location of CSV file containing the servers information. Should contain the following values (example):

Hostname iLOIP NUMAGroupSizeOptimization NodeInterleaving IntelHyperthreading
ESXi-01 100.0.0.1 Clustered Disabled Disabled

LogPath

Location to place the script log file

BiosStatusPath

Location to place the Bios Status after deployment

OUTPUTS

Log file will be created @ $LogPath Bios Status will be created @ $BiosStatusPath

<#
.SYNOPSIS
Configure HP Bios Settings
.DESCRIPTION
This script will take IP parameters from .CSV file and configure various BIOS options on HP DL360 / DL380 Server (Gen9)
You must configure iLO IP and all servers must have the same iLO Admin credentials
Servers must be turned off before running the script
UEFI Boot Order Modifications:
The default boot order is to boot from RAID device and then 10GB Ethernet #1 Interface. This setup assumes RAID located in position #2 and 10GB Ethernet in location #3 in the current UEFI Boot Order. If you need to modify it, please run Get-Help Set-HPBIOSUEFIBootOrder - Detailed for cmdlet explanation and follow the steps there
.PARAMETER Servers_CSV
Location of CSV file containing the servers information. Should contain the following values (example):
Hostname,iLOIP,NUMAGroupSizeOptimization,NodeInterleaving,IntelHyperthreading
ESXi-01,100.0.0.1,Clustered,Disabled,Disabled
.PARAMETER LogPath
Location to place the script log file
.PARAMETER BiosStatusPath
Location to place the Bios Status after deployment
.INPUTS
Parameters above
.OUTPUTS
Log file will be created @ $LogPath
Bios Status will be created @ $BiosStatusPath
.NOTES
Version: 1.0
Author: Omer Barel
Creation Date: January 11th, 2018
Purpose/Change: Production Version
.EXAMPLE
.\SetBiosConfiguration.ps1
Executing the script with default parameters values
.EXAMPLE
.\SetBiosConfiguration.ps1 -Servers_CSV "C:\Temp\Servers.csv" -LogPath "C:\Temp\Log.log" -BiosStatusPath "C:\Temp\BiosStatus.csv"
Executing the script with modified parameters values
#>
#----------------------------------------------------------[Parameters and functions]----------------------------------------------------------
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,Position=1)]
[string]$Servers_CSV="C:Temp\Bios.csv",
[Parameter(Mandatory=$false,Position=2)]
[string]$LogPath="C:\Temp\Bios_Configuration.log",
[Parameter(Mandatory=$false,Position=3)]
[string]$BiosStatusPath="C:\Temp\Bios_Status.csv"
)
$iLOCred = Get-Credential -Message "Please enter iLO Admin Credentials"
$Servers = Import-Csv -Path $Servers_CSV
$Arraycollection = @()
Function Write-Log {
<#
.Synopsis
Write-Log writes a message to a specified log file with the current time stamp.
.DESCRIPTION
The Write-Log function is designed to add logging capability to other scripts.
In addition to writing output and/or verbose you can write to a log file for
later debugging.
.NOTES
Created by: Jason Wasser @wasserja
Modified: 11/24/2015 09:30:19 AM
Changelog:
* Code simplification and clarification - thanks to @juneb_get_help
* Added documentation.
* Renamed LogPath parameter to Path to keep it standard - thanks to @JeffHicks
* Revised the Force switch to work as it should - thanks to @JeffHicks
To Do:
* Add error handling if trying to create a log file in a inaccessible location.
* Add ability to write $Message to $Verbose or $Error pipelines to eliminate
duplicates.
.PARAMETER Message
Message is the content that you wish to add to the log file.
.PARAMETER Path
The path to the log file to which you would like to write. By default the function will
create the path and file if it does not exist.
.PARAMETER Level
Specify the criticality of the log information being written to the log (i.e. Error, Warning, Informational)
.PARAMETER NoClobber
Use NoClobber if you do not wish to overwrite an existing file.
.EXAMPLE
Write-Log -Message 'Log message'
Writes the message to c:\Logs\PowerShellLog.log.
.EXAMPLE
Write-Log -Message 'Restarting Server.' -Path c:\Logs\Scriptoutput.log
Writes the content to the specified log file and creates the path and file specified.
.EXAMPLE
Write-Log -Message 'Folder does not exist.' -Path c:\Logs\Script.log -Level Error
Writes the message to the specified log file as an error message, and writes the message to the error pipeline.
.LINK
https://gallery.technet.microsoft.com/scriptcenter/Write-Log-PowerShell-999c32d0
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[Alias("LogContent")]
[string]$Message,
[Parameter(Mandatory = $false)]
[Alias('LogPath')]
[string]$Path = 'C:\Logs\PowerShellLog.log',
[Parameter(Mandatory = $false)]
[ValidateSet("Error", "Warn", "Info")]
[string]$Level = "Info",
[Parameter(Mandatory = $false)]
[switch]$NoClobber
)
Begin {
# Set VerbosePreference to Continue so that verbose messages are displayed.
$VerbosePreference = 'Continue'
}
Process {
# If the file already exists and NoClobber was specified, do not write to the log.
if ((Test-Path $Path) -AND $NoClobber) {
Write-Error "Log file $Path already exists, and you specified NoClobber. Either delete the file or specify a different name."
Return
}
# If attempting to write to a log file in a folder/path that doesn't exist create the file including the path.
elseif (!(Test-Path $Path)) {
Write-Verbose "Creating $Path."
$NewLogFile = New-Item $Path -Force -ItemType File
}
else {
# Nothing to see here yet.
}
# Format Date for our Log File
$FormattedDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# Write message to error, warning, or verbose pipeline and specify $LevelText
switch ($Level) {
'Error' {
Write-Error $Message
$LevelText = 'ERROR:'
}
'Warn' {
Write-Warning $Message
$LevelText = 'WARNING:'
}
'Info' {
Write-Verbose $Message
$LevelText = 'INFO:'
}
}
# Write log entry to $Path
"$FormattedDate $LevelText $Message" | Out-File -FilePath $Path -Append
}
End {
}
}
Function Set-BiosConfiguration {
#----------------------------------------------------------[Parameters and functions]----------------------------------------------------------
[CmdletBinding()]
Param($Hostname,$BiosConnection,$NumaState,$NodeState,$HyperThreadingState)
#-----------------------------------------------------------[Execution]------------------------------------------------------------
Write-Log -Message "Setting BIOS to UEFI Mode" -Path $LogPath
Set-HPBIOSBootMode -Connection $BiosConnection -BootMode UEFI_Mode
Write-Log -Message "Enabling Optimized UEFI Boot" -Path $LogPath
Set-HPBIOSUEFIOptimizedBoot -Connection $BiosConnection -UEFIOptimizedBoot Enabled
Write-Log -Message "Configuring to boot from RAID and afterwards 10GB Ethernet #1. Assuming boot order #2 for RAID and #3 for 10GB Ethernet" -Path $LogPath
Write-Log -Message "If you need to modify please refer to script documentation" -Path $LogPath
Set-HPBIOSBootOrderPolicy -Connection $BiosConnection -BootOrderPolicy Retry_Indefinitely
Set-HPBIOSNetworkBootOption -Connection $BiosConnection -UEFIPXEBootPolicy IPv4 -PreBootNetworkInterface EmbeddedFlexLOM1
Set-HPBIOSUEFIBootOrder -Connection $BiosConnection -UEFIBootOrder "2,3" # (2=Raid, 3=10GB IPv4)
Write-Log -Message "Configuring server to stay off after power failure" -Path $LogPath
Set-HPBIOSServerAvailability -Connection $BiosConnection -ASR Disabled -AutomaticPowerOn Always_Remain_Off
Write-Log -Message "Configuring Virtualization" -Path $LogPath
Set-HPBIOSVirtualization -Connection $BiosConnection -CPU_Virtualization Enabled -Intel_VT_d2 Enabled -SR_IOV Enabled
Write-Log -Message "Configuring NUMA to $NumaState" -Path $LogPath
Set-HPBIOSAdvancedPerformanceTuningOption -Connection $BiosConnection -NUMAGroupSizeOptimization $Server.NUMAGroupSizeOptimization
Write-Log -Message "Configuring Node Interleaving to $NodeState" -Path $LogPath
Set-HPBIOSNodeInterleaving -Connection $BiosConnection -NodeInterleaving $Server.NodeInterleaving
Write-Log -Message "Configuring HyperThreading to $HyperThreadingState" -Path $LogPath
Set-HPBIOSProcessorOption -Connection $BiosConnection -IntelHyperthreading $Server.IntelHyperthreading
}
Function Get-BiosConfiguration {
#----------------------------------------------------------[Parameters and functions]----------------------------------------------------------
[CmdletBinding()]
Param($Hostname,$BiosConnection)
#-----------------------------------------------------------[Execution]------------------------------------------------------------
$Arrayobject = "" | Select Hostname, iLOIP, BootMode, UEFIOptimizedBoot, BootOrderPolicy, UEFIPXEBootPolicy, PreBootNetworkInterface,
UEFIBootOrder1, UEFIBootOrder2, UEFIBootOrder3, UEFIBootOrder4, UEFIBootOrder5,
AutomaticServerRecovery, AutomaticPowerOn, IOVirtualization, CPUVirtualization, IntelVT, NUMAGroupSizeOptimization, NodeInterleaving, IntelHyperthreading
$Arrayobject.Hostname = $Hostname
$Arrayobject.iLOIP = (Get-HPBIOSAdvancedPerformanceTuningOption -Connection $BiosConnection).IP
$Arrayobject.BootMode = (Get-HPBIOSBootMode -Connection $BiosConnection).BootMode
$Arrayobject.UEFIOptimizedBoot = (Get-HPBIOSUEFIOptimizedBoot -Connection $BiosConnection).UEFIOptimizedBoot
$Arrayobject.BootOrderPolicy = (Get-HPBIOSBootOrderPolicy -Connection $BiosConnection).BootOrderPolicy
$Arrayobject.UEFIPXEBootPolicy = (Get-HPBIOSNetworkBootOption -Connection $BiosConnection).UEFIPXEBootPolicy
$Arrayobject.PreBootNetworkInterface = (Get-HPBIOSNetworkBootOption -Connection $BiosConnection).PreBootNetworkInterface
for ($Counter = 0; $Counter -le 4; $Counter++) {
$UEFIBootOrderSubObjectIndex = $Counter + 1
$UEFIBootOrderSubObject = "UEFIBootOrder" + $UEFIBootOrderSubObjectIndex
$Arrayobject.$UEFIBootOrderSubObject = (Get-HPBIOSUEFIBootOrder -Connection $BiosConnection).UEFIBootOrder[$Counter].DeviceName
}
$Arrayobject.AutomaticServerRecovery = (Get-HPBIOSServerAvailability -Connection $BiosConnection).ASR
$Arrayobject.AutomaticPowerOn = (Get-HPBIOSServerAvailability -Connection $BiosConnection).AutomaticPowerOn
$Arrayobject.IOVirtualization = (Get-HPBIOSVirtualization -Connection $BiosConnection).SR_IOV
$Arrayobject.CPUVirtualization = (Get-HPBIOSVirtualization -Connection $BiosConnection).CPU_Virtualization
$Arrayobject.IntelVT = (Get-HPBIOSVirtualization -Connection $BiosConnection).Intel_VT_d2
$Arrayobject.NUMAGroupSizeOptimization = (Get-HPBIOSAdvancedPerformanceTuningOption -Connection $BiosConnection).NUMAGroupSizeOptimization
$Arrayobject.NodeInterleaving = (Get-HPBIOSNodeInterleaving -Connection $BiosConnection).NodeInterleaving
$Arrayobject.IntelHyperthreading = (Get-HPBIOSProcessorOption -Connection $BiosConnection).IntelHyperthreading
return $Arrayobject
}
#-----------------------------------------------------------[Execution]------------------------------------------------------------
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Confirm:$false -Force
foreach ($Server in $Servers) {
$Hostname = $Server.Hostname
Write-Log -Message "Starting BIOS Configuration Process on Server $Hostname" -Path $LogPath
$BiosConnection = Connect-HPBIOS -Credential $iLOCred -IP $Server.iLOIP -DisableCertificateAuthentication -Force
Write-Log -Message "Reseting BIOS Configuration and rebooting. Script will continue in 7 minutes" -Path $LogPath
Reset-HPBIOSDefaultManufacturingSetting -Connection $BiosConnection -ResetDefaultManufacturingSetting
Set-HPiLOHostPower -Server $Server.iLOIP -Credential $iLOCred -HostPower On -DisableCertificateAuthentication
Start-Sleep -Seconds 420
Write-Log -Message "Applying Bios specifications" -Path $LogPath
Set-BiosConfiguration -Hostname $Hostname -BiosConnection $BiosConnection -NumaState $Server.NUMAGroupSizeOptimization -NodeState $Server.NodeInterleaving -HyperThreadingState $Server.IntelHyperthreading
Write-Log -Message "Adding $Hostname Bios data to file" -Path $LogPath
$HostData = Get-BiosConfiguration -Hostname $Hostname -BiosConnection $BiosConnection
$Arraycollection += $HostData
Write-Log -Message "Closing BIOS Connection to server $Hostname" -Path $LogPath
Disconnect-HPBIOS -Connection $BiosConnection
Write-Log -Message "Rebooting the server to apply configuration" -Path $LogPath
Reset-HPiLOServer -Server $Server.iLOIP -Credential $iLOCred -DisableCertificateAuthentication
}
Write-Log -Message "Writing Data to file..." -Path $LogPath
$Arraycollection | Export-Csv -Path $BiosStatusPath -NoTypeInformation
Write-Log -Message "Excution Completed. Data can found in $BiosStatusPath" -Path $LogPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment