VMware Cloud Community
ZAK-Admin
Contributor
Contributor
Jump to solution

script to disable vnicen.sh help is needed

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ZAK-Admin
Contributor
Contributor
Jump to solution

no problem to start it. I just mentioned it's stopped to keep it's start as part of the script.

 

Much appreciated LucD

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ZAK-Admin
Contributor
Contributor
Jump to solution

Thanks LucD, Mission Accomplished. 😁

0 Kudos
maksym007
Expert
Expert
Jump to solution

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 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos