I have created a solution for this in TypeScript using the Aria Build Tools
https://github.com/vmware/build-tools-for-vmware-aria
private VcHostSystemServiceStart(@notNull @notEmpty @required objVcHostSystem: VcHostSystem, @notNull @notEmpty @required strServiceName: string): void {
let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;
let objVcHostServiceSystem: VcHostServiceSystem = objVcHostConfigManager.serviceSystem;
let objVcHostServiceInfo: VcHostServiceInfo = objVcHostServiceSystem.serviceInfo;
let arrVcHostService: VcHostService[] = objVcHostServiceInfo.service;
let objVcHostService: VcHostService = arrVcHostService.find((objVcHostService: VcHostService): boolean => {
return objVcHostService.key === strServiceName;
});
this.objLogger.info(`Attempting to Start Service on host: '${objVcHostSystem.name}'...`);
if (objVcHostService.policy != "off") {
objVcHostServiceSystem.updateServicePolicy(strServiceName, "on");
}
if (objVcHostService.running == true) {
objVcHostServiceSystem.startService(strServiceName);
}
this.objLogger.info(`Succesfully Start Service on host: '${objVcHostSystem.name}'. `);
}
private VcHostSystemServiceStop(@notNull @notEmpty @required objVcHostSystem: VcHostSystem, @notNull @notEmpty @required strServiceName: string): void {
let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;
let objVcHostServiceSystem: VcHostServiceSystem = objVcHostConfigManager.serviceSystem;
let objVcHostServiceInfo: VcHostServiceInfo = objVcHostServiceSystem.serviceInfo;
let arrVcHostService: VcHostService[] = objVcHostServiceInfo.service;
let objVcHostService: VcHostService = arrVcHostService.find((objVcHostService: VcHostService): boolean => {
return objVcHostService.key === strServiceName;
});
this.objLogger.info(`Attempting to Start Service on host: '${objVcHostSystem.name}'...`);
if (objVcHostService.policy != "off") {
objVcHostServiceSystem.updateServicePolicy(strServiceName, "on");
}
if (objVcHostService.running == true) {
objVcHostServiceSystem.startService(strServiceName);
}
this.objLogger.info(`Succesfully Start Service on host: '${objVcHostSystem.name}'. `);
}
private VcHostSystemServiceRestart(@notNull @notEmpty @required objVcHostSystem: VcHostSystem, @notNull @notEmpty @required strServiceName: string): void {
let objVcHostConfigManager: VcHostConfigManager = objVcHostSystem.configManager;
let objVcHostServiceSystem: VcHostServiceSystem = objVcHostConfigManager.serviceSystem;
let objVcHostServiceInfo: VcHostServiceInfo = objVcHostServiceSystem.serviceInfo;
let arrVcHostService: VcHostService[] = objVcHostServiceInfo.service;
let objVcHostService: VcHostService = arrVcHostService.find((objVcHostService: VcHostService): boolean => {
return objVcHostService.key === strServiceName;
});
this.objLogger.info(`Attempting to Restart Service on host: '${objVcHostSystem.name}'...`);
if (objVcHostService.running == true) {
objVcHostServiceSystem.restartService(strServiceName);
}
this.objLogger.info(`Succesfully Restart Service on host: '${objVcHostSystem.name}'. `);
}
------------------------------
Simon Sparks
Automation & Orchestration Consultant
North West England, UK, Europe
Broadcom Employee
------------------------------
Original Message:
Sent: Jan 13, 2023 08:21 AM
From: rkuechler
Subject: Enabling SSH on an ESXi host which is NOT a member in any vCenter - PowerCLI issues / consideration
Hello together
We have a "2-stage" problem, so to speak:
- How can you enable SSH on an ESXi host if this host is not (yet) a member of a vCenter? The only solution we found is that we use PowerCLI instead of JavaScript inside vRO. Are there alternative options?
- If we stick with PowerCLI, we would like to build some single, reusable actions. E.g. a PowerCLI action to enable SSH, another PowerCLI action that does some specific things, and a PowerCLI action that disables SSH.
However, now we are wondering, if one PowerCli Action eanables SSH and then terminates, how can I "tell" the next PowerCLI Action that the previous PowerCLI Action has already logged-in on to the ESXi host? Somehow you have to be able to pass on these login credentials from one action to the next, right?
Please excuse my english, it's not my native language.
Kind regards
Roman