Monthly Archives: March 2018

VMware Scripts

PowerCLI get list of vMotion IP’s in use



$Array = @()
$Clusters = Get-Cluster | Sort Name
ForEach ($Cluster in $Clusters){
$VmHosts = $Cluster | Get-VmHost | Where {$_.ConnectionState -eq “Connected”} | Sort Name
ForEach ($VmHost in $VmHosts){
$Array += Get-VMHostNetworkAdapter -VMHost $VmHost.Name -VMKernel | Where {$_.VMotionEnabled -eq “True”} | select VmHost,IP
}
}
$Array | Out-GridView

 

Source: http://blog.jgriffiths.org/powercli-get-list-of-vmotion-ips-in-use/


Restart Management Agent on ESXi 6.5

since 6.5 you get a error Message when you try to restart the Management Agent with the command: services.sh restart

-> Errors: Invalid operation requested: This ruleset is required and connot be disabled

 

the new command is:
services.sh restart & tail -f /var/log/jumpstart-stdout.log

Source: https://fabianbrash.com/?p=66


Create / check user on all esxi hosts

If you need to create a aditional user on every vSphere host in your enviroment, you can use the following script:

 


#Vcenter name, can be FQDN
$vsphere = "vcenter"
#User to create
$new_user = "seconduser"
#Password for new user
$new_user_passwd = "password"
#Group to add user too
$new_user_grp = "root"

#local host username with rights to create local users
$root_user = "root"
#Password for local host user with rights to create local users
$root_passwd = "password"

 #Get all of the ESX servers (connect using Windows credentials)
connect-viserver $vsphere
$hosts = Get-View -ViewType HostSystem
disconnect-viserver -confirm:$false

# For each ESX server, connect and see if the new account exists.
# If it does, reset the password and ensure the account is granted shell access.
# If it doesn't, create it and add to the root group (this seems to be necessary to allow ssh login in ESX4.0)
$hosts | %{ $_.name } | %{
 echo $_
 connect-viserver -server $_ -user $root_user -password $root_passwd
 if ($?) {
 if (! (get-vmhostaccount | ?{ $_.id -eq $new_user })) {
 new-vmhostaccount -useraccount -id $new_user -password $new_user_passwd -grantshellaccess
 set-vmhostaccount -groupaccount $new_user_grp -assignusers $new_user
 }
 else {
 set-vmhostaccount -useraccount $new_user -password $new_user_passwd -grantshellaccess $true
 }

disconnect-viserver -confirm:$false "*"
 }
}

 

Source: https://vtote.wordpress.com/2013/03/20/create-user-on-hosts/