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