Sunday, April 20, 2014

Deploying and configuring vCenter appliance (VCSA) 5.5 on VMware workstation


I setup my vSphere lab every 2 months due to evaluation expiration of vsphere suite 5.1. This time I thought it’s worth a creating document and share it on blog for version 5.5. I will have 3 VMs on workstation. Active Directory (Windows 2012), Esxi 5.5 server (Check out for installation of esxi 5.1, Installation same as 5.5 http://goo.gl/ML1MNk ) and the third one is vsphere appliance downloaded from Here. I Generally use appliance in lab to save my time and configuration.
Before deploying vCenter server I would like to show you how my vmware workstation network is configured for internal communication.

I use 192.168.33.0/24 network range for all VMs internal communication and use Host only networking.
 

One IP has been assigned to VMnet1 virtual Ethernet card.



Now open OVA file on workstation. It is around 1.8 TB in size.




Once the deployment is completed, I configure Memory, Processor to low (Due to limited resources on my Desktop, It is ok to run in labs Do not try on production, I found one good article to reduce vcenter appliance tomcat memory footprint. Minimizing or reducing vCenter appliance Memory footprint) and network card to host-only network., Create DNS entries (forward and reverse) on DNS server for vCenter server.
Once you poweron appliance, you will require to login and configure IP addresses and other settings on the server.



Username: root
Password: vmware 



It’s very easy to configure IP address just run“/opt/vmware/share/vami/vami_config_net”


IP address configuration


Gateway configuration



Make sure you have provide proper FQDN name of the host or you will face below error while configuration and will have to make the changes later. (Also make sure you have created Forword and reverse entry in the DNS)


Failed to execute '/usr/sbin/vpxd_servicecfg 'ad' 'test' 'vkunal@vcloud.lab' CENSORED 'vcloud.lab'':
VC_CFG_RESULT=309(Error: Invalid hostname. FQDN is required for joining a domain.)

VC_CFG_RESULT=302(Error: Enabling Active Directory failed.)

 



Last step check and verify configuration. By pressing enter or pressing 0 menu. If everything is ok you are ready to configure vCenter services.



Open https://your vcenter server:5480 url link for further configuration.




Click setup wizard (It opens automatically when you login for the first time.)



Use custom configuration



This is vCenter server database settings. I have selected to use embedded (vPostgres) database (Supports 100 vSphere ESXi hosts and 3,000 virtual machines). You can use Oracle as another database type but will require setup Oracle on separate machine. Microsoft SQL is not supported.


This is again default settings for SSO server and password has been given. Remember this password you will require it later when configuring SSO and logging through web client for the first time.

Username: Administrator@vsphere.local


Active Directory settings.
On this summary page make sure everything is ok and press start for deployment.



If everything is good you will get green check box on settings.



You should see services are running and fine.



Now you are ready to access vSphere web client link. https://vCenter hostname or IP:9443/vsphere-client/

Monday, April 14, 2014

Powershell - Compare 2 csv files and list changes



I had huge list of data and require to find out changes. (Sample) As you can see I have 2 csv file with New.csv and old.csv





Below is the inner data of both files. There are some changes between both files.


After running below script on the both file

 $OldCSV = Import-Csv -Path C:\temp\CSV-test\Old.csv   
 $NewCSV = Import-Csv -Path C:\temp\CSV-test\New.csv  
   
 $output = @()  
   forEach ($Column in $OldCsv) {      
     $result = $NewCSV | Where-Object {$Column.Name -eq $_.Name}  
     $CPU = if ($Column.CPU -ne $result.CPU) {"Found Change"}  
     $Powerstate = if ($Column.Powerstate -ne $result.PowerState) {"Previous: " + $Column.powerstate + " | Now:" + $result.powerstate}  
     $output += New-object PSObject -property @{  
       VMname = $Column.Name  
       Powerstate = $powerstate  
       CPU = $cpu  
     }  
   }  
 $output | select-object vmname, CPU, Powerstate | Export-Csv -Path C:\temp\CSV-test\Changes.csv -NoTypeInformation  

Below is the result.


Warning: All the testings are performed in lab environment.

Sunday, April 13, 2014

Collect disk space detail and send it in email Powercli

This script will collect C Drive with less than 20% space on the VM and send email with nice HTML format.

I have improvised this script and can be found it under Versin 2 VM disk space detail send via email Powercli

  #####################################   
  ## http://kunaludapi.blogspot.com   
  ## Version: 1   
  ## Tested this script on   
  ## 1) Powershell v3   
  ## 2) Powercli v5.5   
  ## 3) Vsphere 5.x   
  #####################################  
 Add-PSSnapin vmware.vimautomation.core  
   
 # vCenter username password  
 $vCenterServer = "vCenterserver"  
 $vcenteruser = "domain\user"  
 $vcenterpasswd = "Password"  
   
 #connect vCenter Server  
 Connect-VIServer -Server $vCenterServer -User $vcenteruser -Password $vcenterpasswd  
   
 $FinalResult = @()  
 $Allvms = Get-View -ViewType “VirtualMachine” -filter @{”Guest.GuestState”=”running”; “Guest.GuestFullName”=”Windows"}  
 foreach ($vm in $Allvms) {  
   #Only C disk  
   $DriveC = $vm.Guest.Disk | Where-Object {$_.Diskpath -eq "C:\"}  
     
   #Calculations  
   $Freespace = [math]::Round($DriveC.FreeSpace / 1MB)  
   $Capacity = [math]::Round($DriveC.Capacity / 1MB)  
   $SpaceOverview = "$Freespace" + "/" + "$capacity"  
   $PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)  
   
   #Report for all vms  
   $report = New-Object psobject  
   $report | Add-Member -MemberType NoteProperty -Name "VMName" -Value $VM.Name  
   $report | Add-Member -MemberType NoteProperty -Name "Free(MB)/Total(MB)" -Value $SpaceOverview  
   $report | Add-Member -MemberType NoteProperty -Name "%Free" -Value $PercentFree  
     
   #VMs with less space on C Drive  
   if ($report."%free" -lt 20) {  
     $finalResult += $report  
   }  
 }  
   
 #HTML format  
 $a = "<style>"  
 $a = $a + "BODY{background-color:peachpuff;}"  
 $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"  
 $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"  
 $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"  
 $a = $a + "</style>"  
   
 #Send Email  
 $messageParameters = @{  
 Subject = "Alert! VMs with less than 20% on C drive"  
 Body = $finalResult | ConvertTo-HTML -head $a -Body "<H2>VMs with less than 20% on C drive</H2>"  
 From = "SpaceAlert@email.com"  
 To = "Employee@email.com"  
 SmtpServer = "smtp.exchange.com"  
 }
Send-MailMessage @MessageParameters  

Warning: All the testings are performed in lab environment.

Saturday, April 12, 2014

Download logs from all esxi host to desktop to review it later

I got some issue within my virtual environment, and found something suspicious in the ESXi logs.

But due to limited time I was not able to review the logs on the other esxi server. here I have created a script to download logs from all esxi host to your desktop or shared location. which will be helpful to review them later. 

I have used pscp.exe (kept under c:\windows\system32 folder) tool to connect to download logs.

  #####################################   
  ## http://kunaludapi.blogspot.com   
  ## Version: 1   
  ## Tested this script on   
  ## 1) Powershell v3   
  ## 2) Powercli v5.5   
  ## 3) Vsphere 5.x   
  #####################################  
$vcenteruser = "domain\user"
$vcenterpasswd = "Password"
$vCenterServer = "vCenterserver"

Connect-VIServer -Server $vCenterServer -User $vcenteruser -Password $vcenterpasswd    

 $iplist = Get-VMHost  
 $password = "Newsecret"   
 $user = "root"   
  foreach ($ip in $iplist) {   
   mkdir "c:\temp\logs\$ip"  
   cd "c:\temp\logs\$ip"  
   $SSHservice = Get-VMHost $ip | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"}   
   if ($SSHservice.Running -eq $False) {   
    Get-VMHost $ip | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"} | Start-VMHostService     
   }   
   
   $filesource = "/var/log/*"   
   $filedestination = "c:\temp\"  
   $source = $filedestination+$ip+"\vmkwarning.log"  
   $remoteserver = $user+"@"+$ip  
   $destination = $remoteserver+":"+$filesource  
   $dot = "."  
   Write-output "y" | pscp.exe -r -pw $password $destination $dot  
   Get-VMHost $ip | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"} | Stop-VMHostService -Confirm:$false  
  }   

Warning: All the testings are performed in lab environment.

Shutdown virtual datacenter quickly using script

Warning: All the testings are performed in lab environment, use them at your own risk. This blog is created for knowledge purpose, I will not be responsible for any damage.

I found one question on the vmware community that if it is possible to create a script to graceful shutdown all vm's and Esxi hosts in the vCenter Server

So thought its worth a creating powercli script.


 #####################################  
 ## http://kunaludapi.blogspot.com  
 ## Version: 1  
 ## Tested this script on  
 ##  1) Powershell v3  
 ##  2) Powercli v5.5  
 ##  3) Vsphere 5.x  
 #####################################

Add-PSSnapin vmware.vimautomation.core  
   
 # vCenter username password  
 $vcenteruser = "domain\user"  
 $vcenterpasswd = "Password"  
   
 # esxi host usernamd password  
 $esxiuser = "root"  
 $esxipasswd = "password"  
   
 #add your vcenter hostname /  
 $vCenterServer = "vCenterserver"  
 $vCenterDatabase = "vCenterDatabase"  
   
 #connect vCenter Server  
 Connect-VIServer -Server $vCenterServer -User $vcenteruser -Password $vcenterpasswd  
   
 #Gracefull shutdown all vms except vCenterserver  
 Get-VM | Where-Object {$_.name -ne $vCenterServer -and $_.name -ne $vCenterDatabase} | Shutdown-VMGuest -Confirm:$false  
 Start-Sleep -s 300  
   
 #Shutdown all Hosts except the esxi where vCenterserver is running.  
 #Make sure Vcenter and its database are on same host.  
 Get-VMHost | Where-Object {$_.Name -ne (Get-VM $vCenterServer | Get-VMHost).Name} | Stop-VMHost -Confirm:$false -Force  
 $esxihost = (Get-VM $vCenterServer | Get-VMHost).Name  
 Disconnect-VIServer $vCenterServer -Confirm:$false  
   
 #Connect to esxi host where vCenter and its database is hosting  
 Connect-VIServer -Server $esxihost -User $esxiuser -Password $esxipasswd  
   
 #Shutdown vcenter and database server  
 Get-VM | Shutdown-VMGuest -Confirm:$false  
 Start-Sleep -s 300  
   
 #shutdown last remaing host.  
 Get-VMHost | Stop-VMHost -Confirm:$false -Force  
 Disconnect-VIServer $ -Confirm:$false  

Below screenshot tells you how it will shutdown your vmware virtual datacenter.


Friday, April 4, 2014

vExpert 2014

Corey Romero, John Troyer, and the VMware Social Media & Community Team have named 754 vExperts on On April 1, the vExperts 2014 are announced. For the first time, I have been elected for my modest contribution to the amazing VMware community. I feel proud, honored and humbled at the same time.
Congratulations to all the other vExperts! Let’s continue and make it an awesome 2014.
The announcement and the complete list of vExperts can be found http://blogs.vmware.com/vmtn/2014/04/vexpert-2014-announcement.html
I would like to thank all of you for making this possible.

VMware-vExpert-2014-400x57