Showing posts with label VMWare. Show all posts
Showing posts with label VMWare. Show all posts

Friday, January 3, 2020

How to check what services are running in VCSA.



SSH into your VCSA and enter the shell.  Type in the following command.
service-control --status --all

To start a service type in the following command.
service-control --start <service name>

VxRail iDRAC cold reset


If you're experiencing weird issues with your iDRAC(i.e. reporting false hardware failure information) you might want to give it a reboot. From VxRail, SSH into the ESX host and do the following.

      cd /opt/vxrail/tools/
      ipmitools mc reset

The iDRAC will get disconnected and will reboot. This generally takes 3-4 mins. The server and its services will remain running.

Monday, November 26, 2018

How to get network statistics on a VM nic from SSH.


If you need to get the network statistics via SSH on a VM nic, run the commands below.

  1. 'esxcli network vm list' to get VM ID.
  2. 'esxcli network vm port list -w <VM ID>' to get port ID number.
  3. 'esxcli network port stats get -p <port ID number>' to get network statistics.
Output:
Packet statistics for port 50332931
   Packets received: 293182742829
   Packets sent: 90336672427
   Bytes received: 305397539251
   Bytes sent: 11805570153
   Broadcast packets received: 135893129
   Broadcast packets sent: 813717
   Multicast packets received: 386654045
   Multicast packets sent: 334554
   Unicast packets received: 292660195655
   Unicast packets sent: 90335524156
   Receive packets dropped: 0
   Transmit packets dropped: 0


Friday, November 9, 2018

How to reinventory/register a vm from the CLI.


To re-inventory/register a vm from the CLI, do the following from an ssh prompt.

  • vim-cmd vmsvc/getallvms | grep -i <VM Name>  to get the VM ID.
  • vim-cmd vmsvc/reload <VM ID>

Tested on ESX 5.0.x - 5.5.x

Thursday, July 12, 2018

Power on a batch of VM's using Powershell


If you have a list of vm's and you need it to be powered on, the script below will help you do that.  To give the storage system air to breathe and not cause a boot storm, it powers on a VM every 2 seconds and waits 5 minutes after ever 50 VM is powered on.

Import-Module vmware.vimautomation.core
Remove-Variable * -ErrorAction SilentlyContinue
$vcenter = "hostname of vCenter or ESX host"
connect-viserver $vcenter
$count = 0
$csvfile = import-csv "Path to csv file"
foreach($vm in $csvfile)
{
    $vm_info = Get-VM -Name $vm.VMName   #VMName refers to column header in the  csv file.
    if ($vm_info.PowerState -eq "PoweredOff")
    {
        Write-Host "Powering on "$vm_info.Name
        $poweron = Get-VM $vm_info.Name | Start-VM -Confirm:$false
        Sleep 2             #power on a vm every 2 seconds.
        $count++
        if($count -eq 50)   #powers on 50 vm's then waits for 5 minutes for  storage to breathe.
        {
            Sleep 300
            $count = 0
        }
    }
}

Tuesday, July 3, 2018

Power on a batch of virtual machines in a csv file using PowerCLI.

Use the following PowerCLI script to power on a list of Virtual Machines from a CSV file.

import-module vmware.vimautomation.core

$vcenter = <my vCenter server>
connect-viserver $vcenter
$allvms = import-csv RVTools_tabvInfo.csv

foreach ($strNewVMName in $allvms)
{   
        #gets all the VM's properties.  We're interested in the PowerState  Property.
        $vmdata = Get-view -ViewType VirtualMachine -Filter @{"name" =  $strNewVMName.vm}  #vm is the column header name in the csv on the first line.
        #if the PowerState is not PoweredOn, then power it on.
        if ($vmdata.Runtime.PowerState -ne "PoweredOn")
        {
            Write-Host "Powering on "$strNewVMName.vm
            Start-VM -VM $strNewVMName.vm
            Sleep 2
        }
}

Wednesday, May 2, 2018

Change Network Failover Detection Policy on vSwitches and portgroups.



Need to change the NetworkFailoverDetectionPolicy for all your vSwithes and portgroups?  The following script traverses all clusters and host to check the NetworkFailoverDetectionPolicy for Beacon Probing.  If its Beacon Probing, change it to Link Status.

#import-module VMware.VimAutomation.Core
#Connect-VIServer -Server vcenter_hostname
#uncomment for testing
#$vmhosts = "hostname1","hostname2"
 
#uncomment for live run
#get the hostnames of all the hosts in every cluster
$vmhosts = get-cluster | get-vmhost | select name
foreach($vmhost in $vmhosts)
{
    #Gets all the vSwitch names that has beacon probing set on the host.
    $switch_policy = Get-VirtualSwitch -VMHost $vmhost.Name | where {$_.Name -ne "vSwitchiDRACvusb"} | Get-NicTeamingPolicy | Where-Object {$_.NetworkFailoverDetectionPolicy -eq "BeaconProbing"} | select -ExpandProperty VirtualSwitch # | select VirtualSwitch | format-wide
    if ($switch_policy)
    {
        foreach ($switch in $switch_policy)
        {
            $vs = Get-VirtualSwitch -VMHost $vmhost.Name -Name $switch
            Get-NicTeamingPolicy -VirtualSwitch $vs | Set-NicTeamingPolicy -NetworkFailoverDetectionPolicy LinkStatus
        }
    }
 
    #Gets all the port group names that has beacon probing set on the host.
    $portgroup_policy = Get-VirtualPortGroup -VMHost $vmhost | Get-NicTeamingPolicy | Where-Object {$_.NetworkFailoverDetectionPolicy -eq "BeaconProbing"} | select -ExpandProperty VirtualPortGroup
    if ($portgroup_policy)
    {
        foreach ($p in $portgroup_policy)
        {
            #Sets the nicteamingpolicy from the host and its portgroup.
            $vpg = Get-VirtualPortGroup -VMHost $vmhost.Name -Name $p
            Get-NicTeamingPolicy -VirtualPortGroup $vpg | Set-NicTeamingPolicy -NetworkFailoverDetectionPolicy LinkStatus
        }
    }
}

Find overcommited compute resources in VMWare.



The following commands requires PowerCLI to run.

Get-MemoryOvercommit -Cluster "Cluster Name"
Get-CPUOvercommit -Cluster "Cluster Name"



Tuesday, April 17, 2018

VMWare vSphere 6.7 is out.

Some new features of vSphere 6.7
-HTML 5 Client
        More features enabled such as vSAN and core storage.
-UNMAP Enhancements
        Able to adjust reclaim rate.  6.5 has a rate of 25MBps.  6.7 can go to 2GBps.
-vSAN 6.7
        QOS Resyncing of data.
        On-Disk Format 6
                -No more actual data moves or evacuation to upgrade a disk format.  Going forward, it will just be meta-data upgrades.
        FIPS 140-2 Encryption.
        

Monday, January 8, 2018

Disable SSL on VMWare Converter.

Disabling SSL on VMWare converter can result in faster conversion speeds.

Go to 
C:\ProgramData\VMware\VMware vCenter Converter Standalone\converter-worker.xml
Change   
     <useSsl>true</useSsl>
to
     <useSsl>false</useSsl>



vCenter database queries

Log into SQL where the vCenter database is on and run the following query:

How many VMs have been deployed.

    select CREATE_TIME,VM_NAME from VPX_EVENT where EVENT_TYPE='vim.event.VMBeingDeployedEvent' and CREATE_TIME>='2012-01-01' and CREATE_TIME<='2013-01-01' and VM_NAME     like 'searchname%' and VM_NAME not like 'vm_name%' and VM_NAME not like 'vm_name%'and VM_NAME not like 'vm_name%' and VM_NAME not like 'vm_name%'    select CREATE_TIME, VM_NAME from VPX_EVENT where EVENT_TYPE= 'vim.event.VMRemovedEvent' and CREATE_TIME >= '2012-01-01' and CREATE_TIME <= '2013-01-01'    select CREATE_TIME, VM_NAME from VPX_EVENT where EVENT_TYPE= 'vim.event.VMCreatedEvent' and CREATE_TIME >= '2012-01-01' and CREATE_TIME <= '2013-01-01'

Memory usage for the year.

    select sample_time, stat_name, stat_value from VPXV_HIST_STAT_YEARLY where stat_group='mem' and stat_name='usage'

Friday, January 5, 2018

Reset vmware ESX evaluation license.

VMWare ESXi license expires in 60 days.  You can reset that 60 days by doing the following.

-ssh into the ESXi host.
-rm -f /etc/vmware/vmware.lic /etc/vmware/license.cfg
-reboot

VMWare - Power ON a vm from the command line

To power on a virtual machine from the command line:

-List the inventory ID of the virtual machine with the command:
               vim-cmd vmsvc/getallvms |grep <vm name>
               Note: The first column of the output shows the vmid.

-Check the power state of the virtual machine with the command:
               vim-cmd vmsvc/power.getstate <vmid>

-Power-on the virtual machine with the command:
               vim-cmd vmsvc/power.on <vmid>

VSS Error while running system state/bare metal restore backup using SCDPM.

When running a system state/bare metal restore backup using SCDPM, you may encounter a VSS error leading to a protection point inconsistency.  This is due to automounter being disabled and the system restore partition being offline in disk management.  The cause of this may be a third party snapshot tool that leverages VSS such as Netapp's SnapDrive.  In order to get SCDPM to do a system state/bare metal restore, you will need to do the following steps.  Note: this works for VMWare converter as well if you're getting

System Partition is offline.  No drive letters

1.  log into the server you want to protect.
2.  open a command prompt
3.  type "diskpart"
4.  type "automount" to display the current state of automount.  If its disabled, open another command prompt and run "diskpart> automount enable" to enable it.
5.  in diskpart, get a list of volumes by typing "list volume".
6.  find the system restore partition and note down the volume number.
7.  type "select volume (x)" where x is the volume number of the system restore partition.
8.  type "online volume" to bring the volume online.
9.  rerun the SCDPM consistency check and it should be successful.

Before

After (Notice "System Reserved" volume is labeled)

Get network info from vmnic using esxcli


Display driver info for network adapter
    esxcli network nic get -n vmnicX

Display network statistics (bytes transferred, errors, packets transferred)
    esxcli network nic stats get -n vmnicX

ESXTOP quick troubleshooting overview


vSAN 6.x cluster shut down and power on procedures

Shutting down the vSAN 6.x cluster

To shut down the vSAN cluster:
  1. Shut down all virtual machines running on the vSAN Cluster.

    Note:The vCenter Server virtual machine must be shut down at the end.

  2. Note the host that your vCenter Server virtual machine resides on. 

    Note: VMware recommends to migrate the vCenter Server virtual machine to the first ESXi host, so you can easily find the virtual machine when powering on your vSAN cluster again.

  3. Ensure that there are no vSAN components currently resynching. For more information, see the Monitor the Resynchronization Tasks in the Virtual SAN Cluster section in the Administering VMware Virtual SAN.
  4. Shut down the vCenter Server virtual machine. This makes the vSphere Web Client unavailable.
  5. Connect to the ESXi host shell. For more information, see  Using ESXi Shell in ESXi 5.x and 6.0 (2004746).
  6. Place all ESXi hosts into Maintenance Mode. This operation must be done using one of the CLI methods that supports setting the vSAN mode when entering Maintenance Mode. You can either do this by logging directly in to the ESXi Shell and running the ESXCLI command locally or you can invoke this operation on a remote system using ESXCLI.
  7. Run this ESXCLI command and ensure that the No Action option is selected when you enter Maintenance Mode:

    # esxcli system maintenanceMode set -e true -m noAction

  8. Shut down all ESXi hosts. You can log in to each ESXi hosts using either the vSphere Client or the ESXi shell. You can also perform this operation remotely using a vSphere API, such as PowerCLI.




Powering on the vSAN 6.x cluster

To power on your vSAN cluster:
  1. Boot up the ESXi hosts through remote console session or physically.
  2. Connect to the shell of each ESXi host and run this command to exit maintenance mode:

    # esxcli system maintenanceMode set -e false

  3. Locate your vCenter virtual machine and power it on using a vSphere client connection directly to the host.
  4. Using the vSphere Client, connect to the ESXi host that contains your vCenter virtual machine. Power on your vCenter Server

    Note: This should be on the first ESXi host, If you moved this virtual machine to that host in step 2 of the shut down procedure.

  5. Connect to your vCenter Server using the vSphere Web Client.

    Note: It may take a few minutes for vCenter Server to become available again

  6. Do a quick health check on the vSAN cluster. Check for network partitions and resyncing components. For more information, see the Monitoring Virtual SAN section of the Administering VMware Virtual SAN.
  7. Power on the remaining virtual machines in the vSAN cluster.


Power off a Virtual SAN Cluster

Power off a Virtual SAN Cluster

Prerequisites
If the vCenter Server VM is running on the Virtual SAN cluster, migrate the VM to the first host, or record the host where it is currently running.
Procedure

1
Power off all virtual machines that are running on the Virtual SAN cluster.
The vCenter Server virtual machine must be powered off last.
2
Place all ESXi hosts that compose the cluster in maintenance mode.
Run the esxcli command to set the Virtual SAN mode for entering the maintenance state.
esxcli system maintenanceMode set -e true -m noAction
3
Power off the ESXi hosts.


To find a VM with a particular snapshot name

Get-Snapshot -VM VM -Name '<snapshot name>'


Power on/off VM via command line.


Power on a VM
To power on a virtual machine from the command line:
  1. List the inventory ID of the virtual machine with the command:

    vim-cmd vmsvc/getallvms |grep <vm name>

    Note: The first column of the output shows the vmid.

  2. Check the power state of the virtual machine with the command:

    vim-cmd vmsvc/power.getstate <vmid>

  3. Power-on the virtual machine with the command:

    vim-cmd vmsvc/power.on <vmid>