Get-esxcli will help us to run the CLI commands over the host directly but to extend it we cannot run certain commands directly over the host, In such case, we can use the below script to run directly on the host and achieve our goals. One shot with the script to achieve multiple targets My target was given to check the status of smartd services in each host and disable it, So I have put the commands on the variable $cmd and $cmd2 and executing it in all the machines, which has been feed in the variable $machines , command get executed in all the hosts fed in the variable $machines . Script : $user = '' $pswd = '' $cmd = 'etc/init.d/smartd status' $cmd2 = 'chkconfig smartd off' $machines = Get-Content "" foreach ( $MACHINE in $machines ) { Get-VMHost -Name $MACHINE | % { $ssh = Get-VMHostService -VMHost $_ | where { $_ . Key -eq 'TSM-SSH' } if ( ! $ssh . Running)
I was working on some weird cases that some of the basic powershell commands are not getting executed in the machine and i came to know that the powershell modules are not getting loaded due to which default modules are not getting loaded in the psmodule path. Resolution would be to run the below commands: $PSModulePath = Get-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" $newPSModulePath = $PSModulePath.PSModulePath + ";C:\Windows\System32\WindowsPowerShell\v1.0\Modules" Set-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" -value $newPSModulePath Else you need to create a PSModulePath value under the below path : HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment and need to enter the value of path mentioned below in the PSModulePath key : %SystemRoot%\system32\WindowsPowerShell\v1.0\M