ZAK-Admin
Contributor
Contributor

script to disable vnicen.sh help is needed

Jump to solution

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

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
4 Replies
LucD
Leadership
Leadership

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

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

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
ZAK-Admin
Contributor
Contributor

Thanks LucD, Mission Accomplished. 😁

0 Kudos