Wednesday, May 30, 2018

Get Complete Virtual Machine inventory of vcenter using vmwarepowercli

Copy below given script and save it as filename.ps1

execute the same script your output of this script will be saved at "c:\vminventory.csv"


You will get below mentioned information from this script.

1.  VMName
2.  IP Address
3.  Domain Name
4.  Real-OS
5.  vCPU
6.  RAM(GB)
7.  Total-HDD(GB)
8.  HDDs(GB)
9.  Datastore
10. Partition/Size
11. Hardware Version
12. PowerState
13. Setting-OS
14. EsxiHost
15. vCenter Server
16. Folder
17. MacAddress
18. VMX
19. VMDK
20. VMTools Status
21. VMTools Version
22. VMTools Version Status
23. VMTools Running Status
24. SnapShots
25. DataCenter
26. vNic
27. PortGroup
28. RDMs


#Add-PSSnapin vmware.vimautomation.core
Connect-Viserver    
#####################################  
 ## http://kunaludapi.blogspot.com  
 ## Version: 1  
 ## Tested this script on  
 ##  1) Powershell v3  
 ##  2) Powercli v5.5  
 ##  3) Vsphere 5.x  
 ####################################
 function Get-VMinventory {  
 function Get-RDMDisk {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual  
         $Result = foreach ($RDM in $RDMInfo) {  
          "{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)     
         }  
         $Result -join (", ")  
 }  
 function Get-vNicInfo {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter  
         $Result = foreach ($vNic in $VnicInfo) {  
           "{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type)  
         }  
         $Result -join (", ")  
 }  
 function Get-InternalHDD {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata  
         $InternalHDD = $VMInfo.ExtensionData.disk   
         $result = foreach ($vdisk in $InternalHDD) {  
           "{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int])  
         }  
         $result -join (", ")  
 }  
   foreach ($vm in (get-vm)) {  
     $props = @{'VMName'=$vm.Name;  
           'IP Address'= $vm.Guest.IPAddress -join ","; #$VM.ExtensionData.Summary.Guest.IpAddress  
           'PowerState'= $vm.PowerState;  
           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';            
           'vCPU'= $vm.NumCpu;  
           'RAM(GB)'= $vm.MemoryGB;  
           'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int];  
           'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "            
           'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", ";  
           'Partition/Size' = Get-InternalHDD -VMName $vm.Name  
           'Real-OS'= $vm.guest.OSFullName;  
           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname;  
           'EsxiHost'= $vm.VMHost;  
           'vCenter Server' = ($vm).ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")  
           'Hardware Version'= $vm.Version;  
           'Folder'= $vm.folder;  
           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", ";  
           'VMX' = $vm.ExtensionData.config.files.VMpathname;  
           'VMDK' = ($vm | Get-HardDisk).filename -join ", ";  
           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus;  
           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion;  
           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus;  
           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus;  
           'SnapShots' = ($vm | get-snapshot).count;  
           'DataCenter' = $vm | Get-Datacenter;  
           'vNic' = Get-VNICinfo -VMName $vm.name;  
           'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", ";  
           'RDMs' = Get-RDMDisk -VMName $VM.name  
           #'Department'= ($vm | Get-Annotation)[0].value;  
           #'Environment'= ($vm | Get-Annotation)[1].value;  
           #'Project'= ($vm | Get-Annotation)[2].value;  
           #'Role'= ($vm | Get-Annotation)[3].value;  
           }  
     $obj = New-Object -TypeName PSObject -Property $Props  
     Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Domain Name', 'Real-OS', 'vCPU', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore', 'Partition/Size', 'Hardware Version', 'PowerState', 'Setting-OS', 'EsxiHost', 'vCenter Server', 'Folder', 'MacAddress', 'VMX', 'VMDK', 'VMTools Status', 'VMTools Version', 'VMTools Version Status', 'VMTools Running Status', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs' # 'Folder', 'Department', 'Environment' 'Environment'  
   }  
 }  
 Get-VMinventory 

 $obj | Sort VMName | Export-Csv -Path "c:\vminventory.csv"

Sunday, May 27, 2018

VMware script to get CPU core details.

Save the given file in machine and give extension ".ps1"

$myCol = @()
Foreach ($cluster in Get-Cluster)
    {
        Foreach($vmhost in ($cluster | Get-VMHost))
        {
            Foreach($vm in (Get-VM -Location $vmhost)){
                $VMView = $vm | Get-View
                $VMSummary = "" | Select ClusterName,HostName,VMName,VMSockets,VMCores,CPUSockets,CPUCores
                $VMSummary.ClusterName = $cluster.Name
                $VMSummary.HostName = $vmhost.Name
                $VMSummary.VMName = $vm.Name
                $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
                $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
                $VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
                $VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
                $myCol += $VMSummary
            }
        }
    }
$myCol | Export-csv reports.csv

Now connect vcenter using vmware powercli and execute the script.


Another method to get done this is follow below mentioned file save and execute the same to get the data.


Don't forget to change the given lines with your scenario.



  • $vcenter = vc01.vcdx56.com
  • $vcenteruser = vcdx56\magnus”
  • $vcenterpw = “not secret”
  • $reportdir = c:\vSpherereport
  • $filename = c:\vSphere$date.html
  • $basefile = c:\vSpherereportCPU-oversubscription.html

 # The script will calculate the ESXi host CPU core to VM vCPU oversubscription and create a HTML report

#
# Version 1.0 Magnus Andersson RTS
#————————————————
# Start of script parameters section
#
# vCenter Server configuration
$vcenter = “vcenter-ip-address“
$vcenteruser = “Administrator@vsphere.local“
$vcenterpw = "password"
#
$date=get-date -uformat %Y-%m-%d
#
# Define report directory
$reportdir = "c:\temp\vSpherereport"
#
# Define file name
$filename = "c:\temp\vSphere$date.html"
#
# Define base file
$basefile = "c:\temp\vSpherereportCPU-oversubscription.html"
#
# End of script parameter section
#—————————————— #
#
# Connect to vCenter Server
connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw
#
function Get-Cluster-CPUMem {
$table = @()
foreach($clust in (get-cluster | Sort-Object Name)) {
$esx = $clust | Get-VMHost
$clu = "" | select Cluster, "ESXi host num CPU core", "VM vCPU", "VM vCPU on", "Percent of vCPU on"
$vms = $clust | get-vm
$clu.Cluster = $clust.Name
$clu."ESXi host num CPU core" = ($clust | Get-vmhost | Measure-Object -Sum NumCPU).Sum
$clu."VM vCPU" = ($vms | Measure-Object -Sum NumCPU).Sum
$clu."VM vCPU on" = ($vms | ?{$_.PowerState -eq "PoweredOn"} | Measure-Object -Sum NumCPU).Sum
$clu."Percent of vCPU on" = "{0:P0}" -f ($clu."VM vCPU on" / $clu."ESXi host num CPU core")
$table += $clu
}
$clu = "" | select Cluster, "ESXi host num CPU core", "VM vCPU", "VM vCPU on", "Percent of vCPU on"
$clu.Cluster = "Total"
$clu."ESXi host num CPU core" = ($table | Measure-Object -property "ESXi host num CPU core" -sum).sum
$clu."VM vCPU" = ($table | Measure-Object -property "VM vCPU" -sum).sum
$clu."VM vCPU on" = ($table | Measure-Object -property "VM vCPU on" -sum).sum
$clu."Percent of vCPU on" = "{0:P0}" -f ($clu."VM vCPU on" / $clu."ESXi host num CPU core")
$table += $clu
$table
}
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 4px;border-style: solid;border-color: black;text-align:center;}"
$a = $a + "</style>"
Get-Cluster-CPUMem | ConvertTo-HTML -head $a -Title "CPU oversubscription report $date" | Out-File $filename
Remove-Item $basefile
Copy-Item $filename $basefile
if ($filename -like "*-01.*") {
Copy-Item $filename $reportdir
}
Remove-item $filename

Friday, May 4, 2018

Update Link Names in Cacti and MRTG

Change ISP link names in MRTG/Cacti



1. Cacti


    Login to Cacti. And select Graphs under Management tab.



   Now select graph which name you wants to update or change.



    To update the title first need to unlock the graph, select Unlock Graph.

    After Unlocking the graph you can edit the Title as mentioned below.



    After necessary changes click on Save to update the graph name.

    Again lock the graph for any accidentally updates in graph.


2. MRTG


To create configuration file check below mentioned command.

/usr/local/mrtg-2/bin/cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: growright,bits' --output /etc/mrtg/mrtg.cfg public@10.200.208.71 public@10.200.208.72
    
Login to MRTG server SSH console to make changes in Link names.



     Edit the mrtg configuration file ( /etc/mrtg/mrtg.cfg)

     Navigate to the title of your link to be modified.




     Save the file after making necessary changes.

     Now do the re-indexing of MRTG to update the link names by below mentioned command.

     /usr/local/mrtg-2/bin/indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

    Now after updating the configuration file, need to arrange the index.html file as per the requirements to see the output in proper and desired format, as i have mentioned below in my scenario.

     /var/www/mrtg/index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>MRTG</TITLE>
    <!-- Command line is easier to read using "View Page Properties" of your browser -->
    <!-- But not all browsers show that information. :-(                             -->
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-15" >
    <META NAME="Command-Line" CONTENT="/usr/local/mrtg-2/bin/indexmaker -output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg" >
    <META HTTP-EQUIV="Refresh" CONTENT="300" >
    <META HTTP-EQUIV="Cache-Control" content="no-cache" >
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache" >
    <META HTTP-EQUIV="Expires" CONTENT="Thu, 11 Jan 2018 14:30:13 GMT" >
    <LINK HREF="favicon.ico" rel="shortcut icon" >
<style type="text/css">
/* commandline was: /usr/local/mrtg-2/bin/indexmaker -output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg */
/* sorry, no style, just abusing this to place the commandline and pass validation */
</style>
</HEAD>
<BODY bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000">

<H1>MRTG GIFT NSE IFSC LINKS</H1>

<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>
<tr>
<td><DIV><B>GIFT_CITY-To-BKC_TCL_100M_P2P</B></DIV>
<DIV><A HREF="10.200.208.71_4.html"><IMG BORDER=1 ALT="10.200.208.71_4 Traffic Graph" SRC="10.200.208.71_4-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.71_4.html" --></SMALL></DIV>
</td>
<td><DIV><B>GIFT_CITY-To-BKC_AirTel_100M_P2P</B></DIV>
<DIV><A HREF="10.200.208.72_4.html"><IMG BORDER=1 ALT="10.200.208.72_4 Traffic Graph" SRC="10.200.208.72_4-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.72_4.html" --></SMALL></DIV>
</td></tr>
<tr>
<td><DIV><B>GIFT_CITY-WAN-ILL-TCL_50M_VPN LINK</B></DIV>
<DIV><A HREF="10.200.208.71_3.html"><IMG BORDER=1 ALT="10.200.208.71_3 Traffic Graph" SRC="10.200.208.71_3-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.71_3.html" --></SMALL></DIV>
</td></tr>
<tr>
<td><DIV><B>GIFT_CITY-To-AHM_TCL_10M_P2P</B></DIV>
<DIV><A HREF="10.200.208.71_6.html"><IMG BORDER=1 ALT="10.200.208.71_6 Traffic Graph" SRC="10.200.208.71_6-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.71_6.html" --></SMALL></DIV>
</td>
<td><DIV><B>GIFT_CITY-To-AHM_AirTel_10M_P2P</B></DIV>
<DIV><A HREF="10.200.208.72_6.html"><IMG BORDER=1 ALT="10.200.208.72_6 Traffic Graph" SRC="10.200.208.72_6-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.72_6.html" --></SMALL></DIV>
</td>
<tr>
<td><DIV><B>GIFY_CITY-To-CHN_TCL_250M_P2P</B></DIV>
<DIV><A HREF="10.200.208.71_5.html"><IMG BORDER=1 ALT="10.200.208.71_5 Traffic Graph" SRC="10.200.208.71_5-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.71_5.html" --></SMALL></DIV>
<td><DIV><B>GIFT_CITY-To-CHN_AirTel_20M_P2P</B></DIV>
<DIV><A HREF="10.200.208.72_5.html"><IMG BORDER=1 ALT="10.200.208.72_5 Traffic Graph" SRC="10.200.208.72_5-day.gif"></A><BR>
<SMALL><!--#flastmod file="10.200.208.72_5.html" --></SMALL></DIV>
</td>
<td>
</td></tr>
</TABLE>
</BODY>
</HTML>

    Now check and verify from the web-console.


























For 64Bit counter support try below syntax.

/usr/local/mrtg-2/bin/cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: growright,bits' --output /etc/mrtg/mrtg1.cfg Chznd^zgup7@10.200.208.71:::::2 Chznd^zgup7@10.200.208.72:::::2

/usr/local/mrtg-2/bin/indexmaker -output=/var/www/mrtg/index.html /etc/mrtg/mrtg1.cfg

/usr/local/mrtg-2/bin/mrtg /etc/mrtg/mrtg1.cfg

Wednesday, May 2, 2018

cron vs anacron

=> Minimum granularity with cron is minute while it is in days with anacron.

=> Cronjob can be scheduled by any normal user while anacron can be scheduled only by the super user.

=> Cron expects the sync to be up & running while the anacron doesn't expect the sys to be up & running all the time. In case of Anacron if a job is schedule and the system is down that time, it will execute the job as soon as the system is up & running.

=> Cron is ideal for servers while anacron is ideal for desktops & Laptops.

=> Cron should be used when you wants a job to be executed at a particular hour and minute anacron should be used in when the job can be executed irrespective of hour and nimute.

VMWare useful definations

Standard Edition: 1 vcenter server in standard license, Up to 2vCPU for FT, vMotion, Storage vMotion, HA, VVols etc.

Enterprise Edition: Same as Standard edition, additionally API's for Array Integration and multipathing DRS and DPM.

Enterprise Plus: Includes all features of Standard and Enterprise with additionally FT upto 4vCPU and 64GB RAM includes distributed vSwitch.

=> Max RAM support in vsphere 6.0 is 12TB

=> To move powered off VM from one host to another is called cold migration. 

=> To move powered on VM from one host to another is called vMotion.

=> Single cluster can manage max 8000 VMs

=> Single cluster can manage max 64 hosts in vsphere 6.0

=> Min 3 Esxi Hosts/Servers in the form of vSAN cluster require. If one of server fails vSAN cluster will fail.

=> Max 64 hosts are allowed to configure a vsan cluster.

=> A Host which has highest numbers of datastores mounted will be selected as a master host.

=> .vmx - Configuration file for a virtual machine

=> .nvram - BIOS related info of Virtual Machine

=> .vmdk - Virtual Machine Disk file and stores data of a Virtual Machine it can be up to 62TB in 6.0

=> vDS (Virtual Distributed Switch) 

Single switch in whole virtual environment  and is responsible to provide central provisioning administration and monitoring of virtual network.

=> VSS (Virtual Standard Switch)

For communication of virtual machines hosted on a single physical host.
- It works like a physical switch automatically detects a VM's which want to communicate with other VM on a same physical server.

=> VVol - (Virtual Volume)

- A new disk management concept introduced in vsphere 6.0 that enables array based operations at the virtual disk level. VVol is automatically  created when virtual disk is created in virtual environment for virtual machine.

=> vSAN (Virtual SAN)

- (I) Hybrid
- Uses both flash-based and magnatic disks for storage, Flash are used for caching while magnatic disks are used for capacity or storage.

- (II) All-Flash
- Uses flash for both caching and for storage.


=> VMKernal adapter

- VMKernel adapter provides network connectivity to the ESXi host to handle network traffic for vMotion, IP Storage, NAS, Fault Tolerance, and vSAN. For each type of traffic such as vMotion, vSAN etc. separate VMKernal adapter should be created and configured.
=> port groups
You can segregate the network traffic by using port groups such as vMotion, FT, management traffic etc.
- Virtual Machine Port Group – Used for Virtual Machine Network
- Service Console Port Group – Used for Service Console Communications
- VMKernel Port Group – Used for VMotion, iSCSI, NFS Communications
=> Hypervisor -

- Hypervisor is a virtualization layer that enables multiple operating systems to share a single hardware host.  Each operating system or VM is allocated physical resources such as memory, CPU, storage etc by the host. There are two types of hypervisors.

- Hosted hypervisor (works as application i-e VMware Workstation)

- Bare-metal (is virtualization software i-e VMvisor, hyper-V which is installed directly onto the hardware and controls all physical resources).

=> VMware HA and FT

- Main difference between VMware HA and FT is: HA is enabled per cluster and VMware FT is enabled per VM. In HA, VMs will be re-started and powered-on on another host in case of host failure, while in FT there is no downtime, because second copy will be activated in case of host failure.
=> Disk Types

- There are three disk types in vSphere.

- Thick Provisioned Lazy Zeroes: every virtual disk is created by default in this disk format. Physical space is allocated to a VM when virtual disk is created. It can’t be converted to thin disk.

- Thick Provision Eager Zeroes: this disk type is used in VMware Fault Tolerance. All required disk space is allocated to a VM at time of creation. It takes more time to create a virtual disk compare to other disk formats.

- Thin provision: It provides on-demand allocation of disk space to a VM. When data size grows, the size of disk will grow. Storage capacity utilization can be up to 100% with thin provisioning.

=> VMware DRS

- DRS stands for Distributed Resource Scheduler; that automatically balances available resources among various hosts by using cluster or resource pools. With the help of HA, DRS can move VMs from one host to another to balance the available resources among VMs.

=> VMware Template

- When a VM is converted into a format which can be used to create a VM with pre-defined settings is called a template. An installed VM can be converted into a template but it cannot be powered-on.

=> Snapshot

- To create a copy of a VM with the time stamp as a restore point is called a snapshot. Snapshots are taken when an upgrade or software installation is required. For better performance, a snapshot should be removed after particular task is performed.

=> How to convert a physical machine into a VM?

- Three steps are required to convert a physical machine to a VM:
- An agent needs to be installed on the Physical machine
- VI client needs to be installed with Converter Plug-in
- A server to import/export virtual machines

=> What monitoring method is used in vSphere HA?

- Network Hearbeat
- Datastore Heartbeat

=> How master host is elected in vSphere HA?

- When HA is enabled in a cluster, all hosts take part in selection process to be selected as a master host. A host which has highest number of datastores mounted, will be selected as a master host. All other hosts will remain slave hosts.

=> VMware Tools

- It is a suite of utilities which are used to enhance performance of a VM in the form of graphics, mouse/keyboard movement, network card and other peripheral devices.


=> ESXi Shell

- It is a command-line interface is used to run repair and diagnostics of ESXi hosts. It can be accessed via DCUI, vCenter Server enable/disable, and via SSH.