Thursday, January 28, 2016

Script to automate to Keep those services on even after reboot in your ESXi

Now for some reason when we were building a data-center for a client they wanted some services to be kept on and running even after reboot of their esxi hosts. This is not a problem if you just have some 10 hosts but what if this datacenter has 100 hosts? I definitely don't want to go to each host and enable them for each host if you want to retain your fingers to do something else other than clicking the mouse.
Here is a quick and dirty way to get that done.
let us run
get-vmhost | get-vmhostservice and you get something like this

KeyLabelPolicyRunningRequired

-----------------------------

DCUIDirect Console UIonTrueFalse

TSMESXi ShellonTrueFalse

TSM-SSHSSHonTrueFalse

lbtdLoad-Based Teaming DaemononTrueFalse

lwsmdActive Directory ServiceoffFalseFalse

ntpdNTP DaemonautomaticTrueFalse

pcscdPC/SC Smart Card DaemonoffFalseFalse

sfcbd-watchdogCIM ServeronFalseFalse

snmpdSNMP ServeronFalseFalse

vmsyslogdSyslog ServeronTrueTrue

vprobedVProbe DaemonoffFalseFalse

vpxaVMware vCenter AgentonTrueFalse

xorgX.Org ServeronFalseFalse

Now let us filter it out to the one that we want. Let us select just the key of the output and ooyah, this is what we get

PS C:\windows\system32> get-vmhost | get-vmhostservice |
select key

Key

---

DCUI

TSM

TSM-SSH

lbtd

lwsmd

ntpd

pcscd

sfcbd-watchdog

snmpd

vmsyslogd

vprobed

vpxa

xorg

Let us say we just want to deal with SSH here and that is the service we want it to be running all the time.

Now you just saved 6-7 clicks per host ;) . have fun.
update
--------
You may want to suppress the warning from the esxi hosts about these services being turned on. I have cooked up a script to do the same. It has the following options.
I have also enabled it to make it possible to target certain clusters or all. Just replace the value * for $cluster with the name of the cluster to perform it on a specific cluster.

Write-Host"

1. Enable SSH

2. Enable SSH+SSH Policy ON

3. Disable SSH+SSH Policy OFF

4. Enable Shell

5. Enable Shell+Shell Policy ON

6. Disable Shell+Shell Policy OFF

7. Disable SSH/Shell warning

8. Reenable SSH/Shell warning

"-ForegroundColorYellow

Write-Host"choose
one of the above"-ForegroundColorYellow

$option=Read-Host""

$cluster="*"

access the same from my github page where i try to keep it updated as and when i can.

About Me

A passionate IT Professional with an endless fetish for innovative Science & Technology.I am a lot of things and a few among them areAn avid gamer,loves photography(not anymore),love a lot of variety of music, movies (foreign),like a lot of manga, anime series and most importantly love life.