Last active
August 29, 2015 14:14
-
-
Save talatham/44c629e05edcc79428fe to your computer and use it in GitHub Desktop.
Disable and stop SSH service on all hosts in a specified vCenter. Input parameter: VC:sdkConnection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Disable SSH on all hosts in a vCenter | |
//Tom Latham (04/02/2015) | |
//Get all host systems from vCenter | |
var hosts = vCenter.getAllHostSystems(null,null); | |
System.log (hosts.length + " hosts found in " + vCenter.name); | |
var countSSHEnabled = 0; //Count of servers with misconfigured SSH | |
var countSSHRemediated = 0; | |
//Iterate across all hosts | |
for each (var host in hosts) | |
{ | |
//DEBUG: Display all host names - System.log (host.name); | |
//Iterate across each service on a host | |
for each (var service in host.configManager.serviceSystem.serviceInfo.service) | |
{ | |
//If the SSH service... | |
if (service.key == 'TSM-SSH') | |
{ | |
//... is not disabled | |
if (service.policy != 'off') | |
{ | |
countSSHEnabled ++; | |
System.log ("Disabling SSH on " + host.name); | |
try{ | |
host.configManager.serviceSystem.updateServicePolicy('TSM-SSH','off'); | |
countSSHRemediated ++; | |
} catch(ex){ | |
System.error ("Error disabling SSH (" + ex + ")"); | |
} | |
} | |
//... is running | |
if (service.running) | |
{ | |
countSSHEnabled ++; | |
System.log ("Stopping SSH on " + host.name); | |
try{ | |
host.configManager.serviceSystem.stopService('TSM-SSH'); | |
countSSHRemediated ++; | |
} catch(ex){ | |
} | |
} | |
} | |
} | |
} | |
System.log (countSSHEnabled + " hosts have SSH enabled or running. " + countSSHRemediated + " have been remediated."); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment