Hello
there's 300 host would like to disable vnicen.sh script with below two commands, any help with powercli script considering
ssh is disabled and hosts with passwords (each host has different password ) are available on csv
/etc/init.d/vnicen.sh stop
chkconfig vnicen.sh off
Thanks & Regards
You could do something like this.
Note that this requires the PoshSSH module to be installed.
The snippet assumes that the CSV contains two columns VMHost and Password.
It also assumes the account to use is 'root'
$cmdSub = @'
/etc/init.d/vnicen.sh stop; chkconfig vnicen.sh off
'@
$pswd = Import-Csv -Path .\pswd.csv -UseCulture
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$sshService = Get-VMHostService -VMHost $esx | where{$_.Key -eq "TSM-SSH"}
if(-not $sshService.Running){
Start-VMHostService -HostService $sshService -Confirm:$false
}
$currentPswd = $pswd | where{$_.VMHost -eq $esx.Name}
if($currentPswd){
$cred = New-Object -TypeName PSCredential -ArgumentList 'root',(ConvertTo-SecureString -String $currentPswd.Password -AsPlainText -Force)
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub
Remove-SSHSession -SSHSession $session | Out-Null
}
else{
Write-Host "Password not found for $($esx.Name)"
}
Stop-VMHostService -HostService $sshService -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Does "ssh is disabled" mean you can't start it temporarily to establish an SSH session?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
no problem to start it. I just mentioned it's stopped to keep it's start as part of the script.
Much appreciated LucD
You could do something like this.
Note that this requires the PoshSSH module to be installed.
The snippet assumes that the CSV contains two columns VMHost and Password.
It also assumes the account to use is 'root'
$cmdSub = @'
/etc/init.d/vnicen.sh stop; chkconfig vnicen.sh off
'@
$pswd = Import-Csv -Path .\pswd.csv -UseCulture
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$sshService = Get-VMHostService -VMHost $esx | where{$_.Key -eq "TSM-SSH"}
if(-not $sshService.Running){
Start-VMHostService -HostService $sshService -Confirm:$false
}
$currentPswd = $pswd | where{$_.VMHost -eq $esx.Name}
if($currentPswd){
$cred = New-Object -TypeName PSCredential -ArgumentList 'root',(ConvertTo-SecureString -String $currentPswd.Password -AsPlainText -Force)
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub
Remove-SSHSession -SSHSession $session | Out-Null
}
else{
Write-Host "Password not found for $($esx.Name)"
}
Stop-VMHostService -HostService $sshService -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, Mission Accomplished. 😁
I have the same question, but another script a bit:
how to check the status for all hosts:
get-vmhost |Sort-Object name |ft -AutoSize name, @{l="module";e={$_ |Get-VMHostModule vnicen.sh |select name, options}}
looks like not the correct one. need your assistance @LucD
To check the status you would have to run
chkconfig --list | grep vnicen
via an SSH session
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference