Update: This script was intended for vSphere 4 and had a bunch of limitations. For a newer version with more functionality check out FixingITpro.com.
PowerCLI, and Powershell in general, are two things I don’t do much with. I’ve used it before when generating a few vSphere Health Check reports but other then that I haven’t played around with it. Today though I was trying setting up a vCenter server and was faced with the daunting task of configuring email alerts from all the alarm settings. This is something that I do on all installs and it normally takes at least 30 minutes because each one has to be done individually.
Not anymore though. I found Chris Uys’s PowerCLI script that can setup vCenter alarms with a single command! Below is the script and to run it you only need to change four fields.
- vCenter IP address
- vCenter Username
- vCenter Password
- Email address to send alerts to
I have modified the script from its original version because it only touched four of the 30 settings in vCenter, my version sets up 17.
How to use it
The first thing to do is download VMware PowerCLI from here. After installing you will have a PowerCLI Icon on your desktop… find it as we will come back to it in a minute.
Next download the script below and extract it to your c:Program Files (x86)VMwareInfrastructurevSphere PowerCLI directory
Right click on the file and edit it with your favorite text editor. You will need to change the following variables to match your environment.
$vCenterServer = “192.168.126.10”$user = “VCENTER USER NAME”
$pass = “VCENTER PASSWORD” $MailToRandom1 = “EMAIL ADDRESS 1”
$MailToDefault1 = “EMAIL ADDRESS 2”
$MailToDefault2 = “EMAIL ADDRESS 3”
Note, If you do not need 3 destination email addresses you will need to remove the other two variables from the script(in all locations). Now save the file.
Now open the PowerCLI icon that you found on your desktop earlier. The first thing we need to do is allow PowerCLI to run unsigned scripts. To do this type:
Set-ExecutionPolicy Unrestricted
You will need to answer ‘Y’ when it prompts you but now we can run our script.
Simply type:
.Set_Email_Alarms.ps1
Now the script will take a few minutes to go through and set the 17 alarms to whenever email addresses you tell it.
Here is the script
Pingback: PowerCLI Script to automatically setup vCenter Alarm Email Notification. « Fixing IT
Thanks Justin. I used your script as a starting point to create one that did things a little differently and with a few more bells and whistles.
http://fixingitpro.com/2012/07/09/powercli-script-to-automatically-setup-vcenter-alarm-email-notification/
Justin,
This script works great and I have used it many times. Do you have a script that will configure all of the alerts for SNMP?
nope but shouldnt be hard to modify he script to do so
Pingback: Spring Cleaning Tips for your VMware Environment | Justin's IT Blog