VMware Cloud Community
LittleOne
Enthusiast
Enthusiast
Jump to solution

create /var/lock/subsys on multiple esxi's

Hello!

I need some help. Basically I need to use powercli to create /var/lock/subsys directory on all esx's from a virtual center. Is it possible?

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm afraid not.

You need to create a SSH connection to the ESXi node, and you need the authority to create a folder.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

The Posh-SSH  module is an option, see start "vpxa" on esxi hosts _powercli


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
zsoltesz
Enthusiast
Enthusiast
Jump to solution

You can use PowerCLI and pLink together to create the directory. In the example below, the $command variable contains the required command to run in the ESXi host. (First you have to start SSH)

The $remoteserver format is root@vmhostname.

$host1|get-vmhostservice| Where { $_.Key -eq "TSM-SSH"}|start-vmhostservice



"yes"|c:\powershell\plink.exe -ssh $remoteserver -pw $pw -m $command



|get-vmhostservice| Where { $_.Key -eq "TSM-SSH"}|stop-vmhostservice -Confirm:$false

0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Hi LittleOne,

I quickly modified the Posh-SSH script LucD was referring to.

<#

Written by Nicholas Mangravit 19.09.2017

PoSH-SSH Required

Tos Install PoSH-SSH Run > Find-Module Posh-SSH | Install Module

#>

#Make sure Psh-SSH is loaded.

if ((Get-Module -Name Posh-SSH -ErrorAction SilentlyContinue) -eq $null) {Import-Module "Posh-SSH" -Force:$true -WarningAction SilentlyContinue}

#VC and ESXi Connection Variables (EDIT THIS SECTION)

$vc = 'vca.vsphere.com'

$Cluster = 'VSAN-Cluster'

$vcCreds = Get-credential -Message "Enter Credentials to connect to vCenter Server" -UserName "administrator@vsphere.com"

$hostCreds = Get-credential -Message "Enter Credentials to connect to ESXi host" -UserName "root"

$sshCommand = "mkdir /var/lock/subsys"

#$sshCommand = "rm -r /var/lock/subsys"

#Connect to vCenter and retrieve ESXi Hosts That are Not Connected or Not Responding

Connect-VIServer $vc -Credential $vcCreds

$vihosts = Get-Cluster $Cluster | Get-VMhost

#Connect to each ESXi Host & Restart Services

foreach ($vihost in $vihosts) {

#If not already Started, Start SSH Server Service on ESXi Host

$sshpolicy = Get-VMHostService -VMHost $vihost | Where {$_.Key -eq "TSM-SSH"}

if($sshpolicy.Running -eq $false){Start-VMHostService $sshpolicy -Confirm:$false}

Start-Sleep -Seconds 1

$ssh = New-SSHSession -ComputerName $vihost -Credential $hostCreds -AcceptKey

Start-Sleep -Seconds 1

Invoke-SSHCommand $ssh -Command $sshCommand

Start-Sleep -Seconds 2

Write-Host -ForegroundColor Green "SSH Command '$sshCommand' was Executed on $vihost"

Start-Sleep -Seconds 2

Remove-SSHSession $ssh

if ($sshpolicy.Running -eq $false) {Stop-VMHostService $sshpolicy -Confirm:$false}

}

#Disconnect from VC and Clear Variables

Write-Host -ForegroundColor yellow "Script Complete Disconnecting fron vCenter $vc"

Disconnect-VIServer $vc -Force -Confirm:$false

Remove-Variable * -Force -ErrorAction SilentlyContinue

Nicholas
0 Kudos
LittleOne
Enthusiast
Enthusiast
Jump to solution

Hey Guys, thanks a lot for you time !!!

I know I'm newbie with powercli trying to do extrange things :-D. This was not easier than I thought it was going to be.

So no chance to create the directory directly from powercli connected to vcenter session without use a root loguin to each esxi host?

Thanks again!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid not.

You need to create a SSH connection to the ESXi node, and you need the authority to create a folder.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Out of interest, what is the reason you want to bypass using root login into the host?

Nicholas
0 Kudos
LittleOne
Enthusiast
Enthusiast
Jump to solution

I need to join more than 200 esx to AD. And face some known issues

To use my own AD group instead of esxAdmins  i used:

Setting = "Config.HostAgent.plugins.hostsvc.esxAdminsGroup"

$value = "MY GROUP"

get-vmhost | Get-AdvancedSetting -Name $Setting | Set-AdvancedSetting -Value $value -Confirm:$false

Then to join the esxi's to specific OU.

$cred=get-credential

get-vmhost | Get-VMHostAuthentication | Set-VMHostAuthentication -JoinDomain -Domain "my.domain.com/BLABLA/SERVERS/SRV-ESXi" -Credential $cred

But I couldn't loguin to the servers, searching about this i found KB: 2075398 and this link

https://www.penguinpunk.net/blog/vmware-joining-an-esxi-5-5-host-to-active-directory-with-powercli/

There is a know issue that need to create a directory "mkdir /var/lock/subsys" and then restart the services.

/etc/init.d/netlogond restart

/etc/init.d/lwiod restart

/etc/init.d/lsassd restart

The command to restart de services.

Get-VMHost | Get-VMHostService | ?{"lsassd","lwiod","netlogond" -contains $_.Key} | Restart-VMHostService

I have almost everything simple to put it into one script and do it in one shot.

0 Kudos