Wednesday, August 27, 2014

Extra Extended VM inventory using powercli - Part 2

In Decemeber 2013 i had published Extended VM inventory using powercli. I observed that script is taking longer than usual, and taking 4-5 hours to pull record from around 900 VMs. 

I tuned up this script and now it is taking around 1.18 hrs to pull the same data. (Faster one)

And also this time I have added many more things than the earlier script.
  • below are the new addition in the scripts
  • Multiple IP address,
  • Name of the hostname inside VM
  • CPUsocket and core count
  • HDD type info
  • Cluster info
  • Annotation attributes information (you will need to fillup these information in notes>custom attributes)
  • vm resource allocation.

  #####################################   
  ## http://kunaludapi.blogspot.com   
  ## Version: 2  
  ## Date: 27 August 2014    
  ## Script tested on below platform   
  ## 1) Powershell v3   
  ## 2) Powercli v5.1   
  ## 3) Vsphere 5.1   
  ####################################  
 Add-PSSnapin vmware.vimautomation.core  
 Connect-Viserver #vcenterserver    
     
   foreach ($vm in Get-VM) {  
     Write-Host $vm.Name  
     #All global info here  
     $GlobalHDDinfo = $vm | Get-HardDisk  
     $vNicInfo = $vm | Get-NetworkAdapter  
     $Snapshotinfo = $vm | Get-Snapshot  
     $Resourceinfo = $vm | Get-VMResourceConfiguration  
       
     #IPinfo  
     $IPs = $vm.Guest.IPAddress -join "," #$vm.Guest.IPAddres[0] <#it will take first ip#>  
   
     #FQDN - AD domain name  
     $OriginalHostName = $($vm.ExtensionData.Guest.Hostname -split '\.')[0]  
     $Domainname = $($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.'  
     
     #All hardisk individual capacity  
     $TotalHDDs = $vm.ProvisionedSpaceGB -as [int]  
     
     #All hardisk individual capacity  
       
     $HDDsGB = $($GlobalHDDinfo | select-object -ExpandProperty CapacityGB) -join " + "  
   
     #All HDD disk type,($vdisk.Capacity /1GB -as [int])}  
     $HDDtype = foreach ($HDDtype in $GlobalHDDinfo) {"{0}={1}GB"-f ($HDDtype.Name), ($HDDtype.StorageFormat)}  
     $HDDtypeResult = $HDDtype -join (", ")  
   
     #Associated Datastores  
     $datastore = $(Get-Datastore -vm $vm) -split ", " -join ", "  
     
     #Guest OS Internal HDD info  
     $internalHDDinfo = ($vm | get-VMGuest).ExtensionData.disk  
     $internalHDD = foreach ($vdisk in $internalHDDinfo) {"{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int])}  
     $internalHDDResult = $internalHDD -join (", ")  
   
     #vCenter Server  
     $vCenter = $vm.ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")   
   
     #VM Macaddress  
     $Macaddress = $vNicInfo.MacAddress -join ", "  
   
     #Vmdks and its location  
     $vmdk = $GlobalHDDinfo.filename -join ", "  
   
     #Snapshot info  
     $snapshot = $Snapshotinfo.count  
     
     #Datacenter info  
     $datacenter = $vm | Get-Datacenter | Select-Object -ExpandProperty name  
   
     #Cluster info  
     $cluster = $vm | Get-Cluster | Select-Object -ExpandProperty name  
   
     #vNic Info  
     $vNics = foreach ($vNic in $VnicInfo) {"{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type)}  
     $vnic = $vNics -join (", ")  
   
     #Virtual Port group Info  
     $portgroup = $vNicInfo.NetworkName -join ", "  
   
     #RDM Disk Info  
     $RDMInfo = $GlobalHDDinfo | Where-Object {$_.DiskType -eq "RawPhysical"-or $_.DiskType -eq "RawVirtual"}   
     $RDMHDDs = foreach ($RDM in $RDMInfo) {"{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)}  
     $RDMs = $RDMHDDs -join (", ")  
   
     #Custom Attributes  
     $Annotation = $vm | Get-Annotation  
     $Project = $Annotation | Where-Object {$_.Name -eq "Project"} | Select-Object -ExpandProperty value  
     $SubProject = $Annotation | Where-Object {$_.Name -eq "SubProject"} | Select-Object -ExpandProperty value  
     $Environment = $Annotation | Where-Object {$_.Name -eq "Environment"} | Select-Object -ExpandProperty value  
     $Application = $Annotation | Where-Object {$_.Name -eq "Application"} | Select-Object -ExpandProperty value  
     $Owner = $Annotation | Where-Object {$_.Name -eq "Owner"} | Select-Object -ExpandProperty value  
     $Creationdate = $Annotation | Where-Object {$_.Name -eq "CreationDate"} | Select-Object -ExpandProperty value  
     $Email = $Annotation | Where-Object {$_.Name -eq "Email"} | Select-Object -ExpandProperty value  
       
     $Vmresult = New-Object PSObject   
     $Vmresult | add-member -MemberType NoteProperty -Name "VMName" -Value $vm.Name  
     $Vmresult | add-member -MemberType NoteProperty -Name "IP Address" -Value $IPs  
     $Vmresult | add-member -MemberType NoteProperty -Name "PowerState" -Value $vm.PowerState  
     $Vmresult | add-member -MemberType NoteProperty -Name "Hostname" -Value $OriginalHostName  
     $Vmresult | add-member -MemberType NoteProperty -Name "Domain Name" -Value $Domainname  
     $Vmresult | add-member -MemberType NoteProperty -Name "vCPU" -Value $vm.NumCpu  
     $Vmresult | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.ExtensionData.config.hardware.NumCPU  
     $Vmresult | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.ExtensionData.config.hardware.NumCoresPerSocket  
     $Vmresult | add-member -MemberType NoteProperty -Name "RAM(GB)" -Value $vm.MemoryGB  
     $Vmresult | add-member -MemberType NoteProperty -Name "Total-HDD(GB)" -Value $TotalHDDs  
     $Vmresult | add-member -MemberType NoteProperty -Name "HDDs(GB)" -Value $HDDsGB  
     $Vmresult | add-member -MemberType NoteProperty -Name "HDDsType" -Value $HDDtypeResult  
     $Vmresult | add-member -MemberType NoteProperty -Name "Datastore" -Value $datastore  
     $Vmresult | add-member -MemberType NoteProperty -Name "Partition/Size" -Value $internalHDDResult  
     $Vmresult | add-member -MemberType NoteProperty -Name "Installed-OS" -Value $vm.guest.OSFullName  
     $Vmresult | add-member -MemberType NoteProperty -Name "Setting-OS" -Value $VM.ExtensionData.summary.config.guestfullname  
     $Vmresult | add-member -MemberType NoteProperty -Name "EsxiHost" -Value $VM.VMHost  
     $Vmresult | add-member -MemberType NoteProperty -Name "vCenter Server" -Value $vCenter  
     $Vmresult | add-member -MemberType NoteProperty -Name "Hardware Version" -Value $vm.Version  
     $Vmresult | add-member -MemberType NoteProperty -Name "Folder" -Value $vm.folder  
     $Vmresult | add-member -MemberType NoteProperty -Name "MacAddress" -Value $macaddress  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMX" -Value $vm.ExtensionData.config.files.VMpathname  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMDK" -Value $vmdk  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Status" -Value $vm.ExtensionData.Guest.ToolsStatus  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Version" -Value $vm.ExtensionData.Guest.ToolsVersion  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Version Status" -Value $vm.ExtensionData.Guest.ToolsVersionStatus  
     $Vmresult | add-member -MemberType NoteProperty -Name "VMTools Running Status" -Value $vm.ExtensionData.Guest.ToolsRunningStatus  
     $Vmresult | add-member -MemberType NoteProperty -Name "SnapShots" -Value $snapshot  
     $Vmresult | add-member -MemberType NoteProperty -Name "datacenter" -Value $datacenter  
     $Vmresult | add-member -MemberType NoteProperty -Name "Cluster" -Value $cluster  
     $Vmresult | add-member -MemberType NoteProperty -Name "vNic" -Value $vNic  
     $Vmresult | add-member -MemberType NoteProperty -Name "Portgroup" -Value $portgroup  
     $Vmresult | add-member -MemberType NoteProperty -Name "RDM" -Value $RDMs  
     $Vmresult | add-member -MemberType NoteProperty -Name "Project" -Value $Project  
     $Vmresult | add-member -MemberType NoteProperty -Name "SubProject" -Value $SubProject  
     $Vmresult | add-member -MemberType NoteProperty -Name "Environment" -Value $Environment  
     $Vmresult | add-member -MemberType NoteProperty -Name "Application" -Value $Application  
     $Vmresult | add-member -MemberType NoteProperty -Name "Email" -Value $Email  
     $Vmresult | add-member -MemberType NoteProperty -Name "Owner" -Value $Owner  
     $Vmresult | add-member -MemberType NoteProperty -Name "CreationDate" -Value $Creationdate  
     $Vmresult | add-member -MemberType NoteProperty -Name "NumCpuShares" -Value $Resourceinfo.NumCpuShares  
     $Vmresult | add-member -MemberType NoteProperty -Name "CpuReservationMhz" -Value $Resourceinfo.CpuReservationMhz  
     $Vmresult | add-member -MemberType NoteProperty -Name "CpuLimitMhz" -Value $Resourceinfo.CpuLimitMhz  
     $Vmresult | add-member -MemberType NoteProperty -Name "CpuSharesLevel" -Value $Resourceinfo.CpuSharesLevel  
     $Vmresult | add-member -MemberType NoteProperty -Name "NumMemShares" -Value $Resourceinfo.NumMemShares  
     $Vmresult | add-member -MemberType NoteProperty -Name "MemReservationGB" -Value $Resourceinfo.MemReservationGB  
     $Vmresult | add-member -MemberType NoteProperty -Name "MemLimitGB" -Value $Resourceinfo.MemLimitGB  
     $Vmresult | add-member -MemberType NoteProperty -Name "MemSharesLevel" -Value $Resourceinfo.MemSharesLevel  
     $Vmresult | add-member -MemberType NoteProperty -Name "NumDiskShares" -Value $Resourceinfo.DiskResourceConfiguration.NumDiskShares  
     $Vmresult | add-member -MemberType NoteProperty -Name "DiskSharesLevel" -Value $Resourceinfo.DiskResourceConfiguration.DiskSharesLevel  
     $Vmresult | add-member -MemberType NoteProperty -Name "CpuAffinityList" -Value $Resourceinfo.CpuAffinityList  
     $Vmresult  
   }  
Result look like below
Stay tuned for Extended VMHost inventory........
Powercli VMHost esxi server inventory
VMware Networking 101: VMware Network Load Balancing policies – Part 1
VMware Networking 101: VLAN handling in vSwitches – Part 2
VMware Networking 101: Network Failure Detection – Part 3

Disclaimer:

This is a personal weblog. The opinions expressed here represent my own. If you find any correction need to be done, Feel free to comment on the post.

Sunday, August 24, 2014

VMware Networking 101: VLAN handling in vSwitches – Part 2



VLAN handling in virtual switches
There are 3 modes of accessing VLANs in vswitches on esxi.

  •          EST (External Switch Tagging)
  •          VST (Virtual Switch Tagging)
  •          VGT (Virtual Guest Tagging)

What is VLAN, Access Port and Trunk Port? (I recommend watching below videos on YouTube for beginners)

EST (External Switch Tagging)
                In this method your physical switch port is configured as Access port, and no VLAN configured on virtual port group, Physical switch handle VLAN tagging. vSwitches receives untagged traffic. Downside of this method it will consume lots of NICs, if you want to use different VLANs. 

VST (Virtual Switch Tagging)
                This is the very common, popular and recommended best method. Virtual Port Groups are configured with VLAN. To work this design connected physical switch port should be configured as Trunk port and can be configured with either one VLAN or multiple VLANs. Traffic with VLAN tag is sent down to vSwitches. vSwitches will forward that traffic to concerned port group by stripping the VLAN tag. Tagging is added when traffic is left from vSwitches to uplink port. There is little CPU cycle involved using this technique.

VGT (Virtual Guest Tagging)
                Configuration for this method is as same as VST at physical switch. Physical switch port should be configured as trunk. Actual VLAN is configured on VM in the virtual NIC settings and VLAN 4095 configured on virtual port group. (4095 can read all VLANs traffic, this VLAN is generally used for monitoring or sniffing traffic)
I found VLAN id option in vmxnet3 Ethernet adapter only.

 
VMware Networking 101: VMware Network Load Balancing policies – Part 1
VMware Networking 101: VLAN handling in vSwitches – Part 2
VMware Networking 101: Network Failure Detection – Part 3
VMware Networking 101: vSwitches or PortGroup Security Settings – Part 4
Disclaimer:

This is a personal weblog. The opinions expressed here represent my own. If you find any correction need to be done or anything inappropriate, Feel free to comment on the post.