Category Archives: powercli

Quickly configuring vCenter alarms using PowerCLI

To quickly configure all vCenter alarms to send an email, use this snippet:

Get-AlarmDefinition | New-AlarmAction -Email -To ''

Once that is in place, set up an AlarmActionTrigger to send an email when the monitored item moves from green to yellow. The default AlarmAction created earlier already contains a setting for moving from yellow to red:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like ''} | New-AlarmActionTrigger -startstatus 'Green' -EndStatus 'Yellow'

To have the alarm action repeat, use the -Repeat flag on the New-AlarmActionTrigger.

To add other transitions, use the New-AlarmActionTrigger and change the -StartStatus and -EndStatus to the desired transition. For example, -StartStatus ‘Red’ -EndStatus ‘Yellow’ will set the alarm to notify “Once” when moving from Red down to Yellow.

To see all Alarms configured to send to a certain email address along with triggers:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | Where-Object {$_.To -like ''} | Select AlarmDefinition,To,Trigger

To remove all SendEmail AlarmActions for a particular email address:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like ''} | Remove-AlarmAction

Further information at

Bulk configuration of HP iLO4

Found myself in a situation where I had 38 new HP DL380 Gen8 servers that needed their iLO4‘s configured to match the standard. While I’m always a fan of repetitive point and clicking (not really), I decided my time would be better spent finding a more efficient way to configure them all at once.

Enter HPQLOCFG.EXE: The HP Lights-Out Configuration Utility. Installed it on a random Win2k8 R2 VM and then downloaded the accompanying scripting examples. Coupled with the HP iLO 4 Scripting and Command Line Guide, it becomes fairly easy to cobble together a master script which remotely fully configures an iLO4 from scratch knowing only the DNS hostname and default Administrator password. Obviously DHCP comes in handy here on the iLO network so the iLO4 can get on the network without ever touching the server.

Reviewing the XML scripting examples, there are many good ones for doing individual configuration of certain features of the iLO4 using RIBXML. Putting them all together in to one script is a fun exercise, but the examples are good and the PDF guide is helpful.

The way it all works is an XML file is prepared by you and then passed to HPLOCFG.exe along with remote iLO4 hostname, Administrator username, and default Administrator password.

Here is an example XML file which fully configures features of the iLO4 to meet the customer’s standard:

	<LOGIN USER_LOGIN="adminname" PASSWORD="password">
		<RIB_INFO MODE="write">
				<ACTIVATE KEY="1111122222333334444455555"/>
				<OS_TRAPS value="Yes"/>
				<RIB_TRAPS value="No"/>
				<CIM_SECURITY_MASK value="3"/>
				<SNMP_SYS_CONTACT VALUE="Server Team"/>
				<TRAP_SOURCE_IDENTIFIER value="iLO Hostname"/>
				<SNMP_ACCESS_ENABLED value="Yes"/>
				<SNMP_PORT value="161"/>
				<SNMP_TRAP_PORT value="162"/>
				<SNMP_V1_TRAPS VALUE="Yes"/>
				<ENABLE_NIC value="Yes"/>
				<REG_DDNS_SERVER value="Yes"/>
				<PING_GATEWAY value="Yes"/>
				<DHCP_DOMAIN_NAME value="No"/>
				<DHCP_ENABLE value="No"/>
				<IP_ADDRESS value="%iloIP%"/>
				<SUBNET_MASK value=""/>
				<GATEWAY_IP_ADDRESS value="%iloGW%"/>
				<DNS_NAME value="%servername%-ilo"/>
				<DOMAIN_NAME value=""/>
				<DHCP_GATEWAY value="No"/>
				<DHCP_DNS_SERVER value="No"/>
				<DHCP_WINS_SERVER value="No"/>
				<DHCP_STATIC_ROUTE value="No"/>
				<DHCP_SNTP_SETTINGS value="No"/>
				<DHCPV6_SNTP_SETTINGS value="No"/>
				<REG_WINS_SERVER value="Yes"/>
				<PRIM_WINS_SERVER value=""/>
				<SEC_WINS_SERVER value=""/>
				<PRIM_DNS_SERVER value=""/>
				<SEC_DNS_SERVER value=""/>
				<SNTP_SERVER1 value=""/>
				<SNTP_SERVER2 value=""/>
				<TIMEZONE value="America/Detroit"/>
		<SERVER_INFO MODE="write">
			<SERVER_NAME value="%servername%"/>
			<SERVER_FQDN value=""/>
		<USER_INFO MODE="write">
			<MOD_USER USER_LOGIN="Administrator">
				<PASSWORD value="adminpwd"/>
			<ADD_USER USER_NAME="monitoring" USER_LOGIN="monitoring" PASSWORD="monitoring">
				<ADMIN_PRIV value="N"/>
				<REMOTE_CONS_PRIV value="N"/>
				<RESET_SERVER_PRIV value="N"/>
				<VIRTUAL_MEDIA_PRIV value="N"/>
				<CONFIG_ILO_PRIV value="N"/>
		<DIR_INFO MODE="write">
				<DIR_LOCAL_USER_ACCT value="Yes"/>
				<DIR_SERVER_ADDRESS value=""/>
				<DIR_SERVER_PORT value="636"/>
				<DIR_USER_CONTEXT_1 value="OU=Teams,OU=EXAMPLE,DC=example,DC=com"/>
				<DIR_ENABLE_GRP_ACCT value="Yes"/>
				<DIR_GRPACCT1_NAME value="CN=ILO_Admins,OU=EXAMPLE,DC=example,DC=com"/>
				<DIR_GRPACCT1_PRIV value="1,2,3,4,5,6"/>
				<DIR_GRPACCT1_SID value="S-1-0"/>
		<SSO_INFO MODE="write">

In the example above, note that some values are represented by variables such as %iloIP%. This allows the actual value to be filled in on the command line dynamically using the -t flag versus hardcoding it in the file. Also note that the <LOGIN> tag is ignored if username & password are used on the HPQLOCFG.exe command line (-u and -p flags).

To run this RIBXML against a virgin iLO4, the command is simply:
C:\Program Files (x86)\HP Lights-Out Configuration Utility>HPQLOCFG.exe -s -u administrator -p 12345678 -f c:\scripts\ilo-scripts\my_config.xml
-t servername=SuperServer,iloIP=,iloGW=,syslogIP=

Note the -t flag and its key=value pairs. Any instances of %servername% will be replaced by “SuperServer”, and so on. Very handy.

Pairing this functionality with Powershell and a CSV file of servername, iLO default password, desired iLO Hostname, iLO IP, iLO Gateway, and anything else necessary gives a powerful bulk-configuration tool which can configure all the iLOs in minutes.

Create a CSV as shown:


Due to some formatting and syntax issues I was running in to with passing values through Powershell, I opted to make a simple “ilo.bat” batch file to take the values from import-csv and ultimately pass them on to HPQLOCFG.exe:

"C:\Program Files (x86)\HP Lights-Out Configuration Utility\HPQLOCFG.exe" -s %1 -u administrator -p %2 -f c:\scripts\ilo-scripts\my_config.xml -t servername=%3,iloIP=%4,iloGW=%5,syslogIP=%6

Then, to run it, use Powershell’s import-csv to parse the CSV, pass the values to the batch file which then passes them to HPQLOCFG.

import-csv -path .\ilo_config.csv | %{ & '.\ilo.bat' $_.iloHostname $_.password $_.servername $_.iloIP $_.iloGW $_.syslogIP }

All iLOs will then be configured! And luckily, if anything gets messed up or the script didn’t work, there is an example Factory_Reset.xml which can set an iLO4 back to defaults (don’t forget the default password – you’ll need it after it’s been reset!)

Change root password on all vSphere ESXi hosts

Adapted from Change root password on all (or some) vSphere h… | VMware Communities.

$vCenter = "vcenterserver"
$oldpw = "oldpwd"
$newpw = "newpwd"

connect-viserver -server $vCenter -Credential (Get-Credential)
$hosts = @() 
write-host "Querying for ESXi hosts..."

Get-VMHost | sort | Where {$_.ConnectionState -eq "Connected" -or $_.ConnectionState -eq "Maintenance"} | Get-View | Where {$_.Summary.Config.Product.Name -match "i"} | % { $hosts+= $_.Name }

Disconnect-VIServer -confirm:$false

foreach ($vmhost in $hosts) {
    write-host "Connecting to $vmhost..."
    connect-viserver -server $vmhost -user root -password "$oldpw"
    write-host "Changing root password on $vmhost..."
    Set-VMHostAccount -UserAccount root -password "$newpw"
    Disconnect-VIServer -confirm:$false

Count of powered-on VMs by host or datastore

Via One Liner: How many VMs ? | Virtu-Al.Net.

If you have an environment with a lot of powered-off VMs, you may only want a count of powered-on VMs per host, instead of a count of the total number of VMs per host:

Get-VMHost | Select @{N="Cluster";E={Get-Cluster -VMHost $_}}, Name, @{N="NumVM";E={($_ | Get-VM | where {$_.powerstate -eq "poweredon"}).Count}} | Sort Cluster, Name

To get a count of powered-on VMs for a datastore:

get-datastore linked_clones | Get-VM | where {$_.powerstate -eq "poweredon"} | measure-object

Set advanced settings on all hosts

Got an advanced setting to change on all hosts? PowerCLI to the rescue:

Get-AdvancedSetting -entity (get-cluster ClusterName | get-vmhost) -name "Advanced.Option" | set-advancedsetting -value 'VALUE_HERE' -confirm:$false