Friday 2 November 2012

Change ODBC DSN User name and Password on vCenter Server and SQL DB

Yesterday I just got messed up with the SQL System DSN of vCenter and SQL Servers but later resolved it somehow. All this lead to little deep dive to SQL authentication from vCenter upto windows registry. Interesting!!

Issue:

I'm using vCHB server (IP 172.x.x5), on both HB  servers I have configured the ODBC DSN SQL with account "vcenter_ID" and  same has been configured in SQL studio as well having proper access to  VC DB that is being used... Everything was running perfect but due to  some security issue we change MS SQL "sa" password and by some other  means we switchover the heartbeat of VC from one server to another HB  server ( this restarted the vCenter Service). Post this, I found that  vCenter service was not coming online.

When I checked the SQL logs, I found "sa" is not able to login from (IP 172.x.x5)

Now I'm confused, why this happened and when I change my "sa" password back to old .. and vCenter Service got started.

I'm  using "vcenter_ID" account in DSN and DB for vcenter connection how it  was affected by changing "sa" password. Can anyone please help me to  sort this out.

S/W version used:
1. vcenter 5.0 patch7
2. sql 2008
3. vCHB Server 6.5.3



Root Cause:

Initially when VC was installed, we used "sa" account but later on in DSN it was changed to "vcenter_ID"... due to this "sa" was stored in registry of SQL server... and was not updated automatically when user changed to "vcenter_ID"


Resolution:

              Change user in vCenter registry

·         Take a full backup of the registry prior to editing it. Do not skip this step.
·         Click Start > Run, type “regedit” and click OK.
·         In the Windows Registry Editor, navigate to:
·         HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware VirtualCenter\DB (under My Computer)
·         For vCenter Server 5.0: HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware VirtualCenter\DB
·         Right-click 2 and click Modify.
·         Enter the database user ID “vcenter_ID” in the Value data field.
·         Click OK.

Now we need to update the password used by the vCenter Server for database connections to the SQL Database in registry following below steps:

·         Click Start, right-click Command Prompt, and select Run as administrator to open a command prompt as an administrator.
·         Run this command:  “C:\Program Files\VMware\Infrastructure\VirtualCenter Server\vpxd.exe –p”
·         Enter a new password when prompted. (password of “vcenter_ID”)



Posted in VM Community as well:




Thursday 6 September 2012

Taking ESXi Config Backup using PowerShell

Taking ESXi Config Backup using PowerShell

Script to back up all your ESXi hosts in your vCenter environment

My test code:
function LoadSnapin{
  param($PSSnapinName)
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
  }
}
# Load PowerCLI snapin
LoadSnapin -PSSnapinName "VMware.VimAutomation.Core"
# Variables
[string] $vCenter = "192.168.131.20"
[string] $BackupPath = "C:\test"
# Connect to vCenter
Connect-VIServer $vCenter -user "vmadmin" -Pass "vmware@123" -Protocol Https
# Get All Connected Hosts
$VMH = Get-VMHost | Sort Name
# For each Host in All Connected Hosts
Foreach ($eVMH in $VMH)
{
    # Backup Host config
    Set-VMHostFirmware -VMHost $eVMH.name -BackupConfiguration -DestinationPath $BackupPath
}
# Disconnect from Host
Disconnect-VIServer -Confirm:$false

Results:












Your code should be like below:
function LoadSnapin{
  param($PSSnapinName)
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
  }
}


# Load PowerCLI snapin
LoadSnapin -PSSnapinName "VMware.VimAutomation.Core"
# Variables
[string] $vCenter = <<”your vCenter IP”>
[string] $BackupPath = "C:\test"
# Connect to vCenter
Connect-VIServer $vCenter -user  <<”Your user name”>> -Pass <<”your password”>> -Protocol Https
# Get All Connected Hosts
$VMH = Get-VMHost -Location RMGADC | Sort Name
# For each Host in All Connected Hosts
Foreach ($eVMH in $VMH)
{
    # Backup Host config
    Set-VMHostFirmware -VMHost $eVMH.name -BackupConfiguration -DestinationPath $BackupPath
}
# Disconnect from Host
Disconnect-VIServer -Confirm:$false

Wednesday 18 July 2012

Pinging NTP server IP from ESXi Shell using PowerShell

We can achieve this using Plink.exe utility. NOTE: root credentials are required to implement this using PS Script:

code is as below:

Connect-VIServer -Server 192.168.131.20 -Protocol https -user "vmadmin" -Pass "vmware@123"


$vmP = Get-VMHost |Sort Name
$str1="c:\plink.exe -v -l root "
$str9=' -pw "vmware@123"'
$str2="ping "
$str3="192.168.131.20"
$outfile="c:\rana.csv"

foreach($esxentry in $vmP){
$esxhost=$esxentry.name
$command=$str1+$esxhost+$str9+$str2+$str3
$esxentry.name >> $outfile
"Ping response from" +"$esxhost" + "to NTP Server" + "$str3" >>$outfile
$result=Invoke-Expression -Command $command
foreach($resultline in 1..$result.length){
$result[$resultline] >> $outfile
}
}


# script will check the ping response from each Hosts added to VC and output will be saved in c:\Rana.CSV
# you need to copy plink.exe utility @ C:\ from where youare triggering this script

========================
OutPut :

Host1.esxi.rana.com
Ping response from Host1.esxi.rana.com to NTP Server192.168.131.20

Host2.esxi.rana.com
Ping response from Host2.esxi.rana.com to NTP Server192.168.131.20
64 bytes from 192.168.131.20: icmp_seq=0 ttl=128 time=0.675 ms
64 bytes from 192.168.131.20: icmp_seq=1 ttl=128 time=0.494 ms
64 bytes from 192.168.131.20: icmp_seq=2 ttl=128 time=0.485 ms

--- 192.168.131.20 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.485/0.551/0.675 ms



in case of no ping response you will find out put like below:
 Host1.esxi.rana.com
Ping response from Host1.esxi.rana.com to NTP Server192.168.131.20


<BLANK>

 Host2.esxi.rana.com
Ping response from Host2.esxi.rana.com to NTP Server192.168.131.20
64 bytes from 192.168.131.20: icmp_seq=0 ttl=128 time=0.675 ms

Wednesday 16 November 2011

How to Find Virtual Center IP from ESX Host


Guys Sometime we forget the VC IP but we know the IP of ESX/ESXi, such situations generally occurs when we are working in large distributed IT infrastructure or if we are working as newly hired for client and do not have adequate knowledge transfer sessions. Even I did this First time and was not aware of this before untill someone asked me to know "how to fetch this info"..





CASE SCENARIO: My VC IP is 192.168.131.20 ( and I do not know about this) and some how I know the ESX IP or name ( ESX IP is 192.168.131.9)




>I chose any one of ESX\ESXi for which I'm looking for VC IP\Name

>log in to ESX\ESXi as root




> type below command:



grep "Manager IP" /var/log/vmware/vpx/vpxa.log



Output :
in above output Manager IP communicating to port 902 using vpxa agent is IP of your VC


~ #
~ # [2011-11-16 13:33:27.094 0x764e2ab0 info 'App'] [VpxaInvtHost] Manager IP: 192.168.131.20:902   Host IP: 192.168.131.9 Preserve IPs: false

~ #
~ #




Wooo !! Looks Good to me now !!!

Tuesday 8 November 2011

Auto upgrade VMware Tools on multiple Virtual Machines on next reboot

This will save huge time and effort of an administrator when he needs to update VMware tools on hundreds of VMs . Here I used PowerShell scripts to achieve the results:



Pre-Requisite :

> Windows Powershell 1.0



> VI Toolkit (login with an account, or registrar it is free)






1>Install VI ToolKit on workstation and PowerShell

2>Start the VI Toolkit

3> Connect to the Virtual Center server with command:

Command Syntax:



connect-viserver -server <VirtualCenter Server IP address> -user <VirtualCenter User> -password <VirtualCenter password>



4>Copy & Paste the following command in Toolkit Window:

 Command Syntax:

Foreach ($v in (get-vm)) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”

$vm.ReconfigVM($vmConfigSpec)

}





press ENTER twice to start execution, Check recent task in VC progress will be shown there.



Now when your VM's Boot next time, tools will automatically installed on them.





5> Question:  Now VMTools will start getting installed every time (in future as well) VMs boot or get restarted. How to avoid this.

Ans: Once tools installed we do not wants VM's to give a check or install instructions every time when it boots. so we need to rollback the task that we did above in PowerShell script



6> to Rollback copy below script in VI toolkit windows:

Command Syntax:

Foreach ($v in (get-vm)) {

$vm = $v | Get-View }

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = “Manual”

$vm.ReconfigVM($vmConfigSpec)

}









Voila!! you are done now..





Additional:



1>you may wants to update VMTools on specific VMs. let's say all VMs with name containing "Desktop" then you need to use below script:

 Command Syntax:

Foreach ($v in (get-vm)) {

If ( $v -like “Desktop*”) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = “manual”

$vm.ReconfigVM($vmConfigSpec)

}

}



2> Another example, if you want set installation on Tools, on all VMs except VMs with name containing "Desktop" then you need to use below script command:

 Command Syntax:

Foreach ($v in (get-vm)) {

If ( $v -notlike “Desktop*”) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”

$vm.ReconfigVM($vmConfigSpec)

}

}