Monday 14 March 2016

vCenter VM Report



#The script is executed from PowerCLI or PowerShell with PowerCLI module.
#It connects to a vCenter server and creates a CSV report in D:\ drive 
#or you may set your preferred location.
#The output file is named "VM_Report_currentDate.csv.".
#The report lists VM names, Windows names (not FQDNs), 
#IPv4 addresses and whatever is written in the Notes filed.

#Set the input value for vCenter variable to string. 

param ([string] $VIServer)

Write-Host
Write-Host

#Get the vCenter server name if PowerCLI is already connected.

$VIServer = $global:DefaultVIServers.Name

#If not already connected to a vCenter server, 
#prompt for vCenter Server FQDN or IP.

If ($VIServer -eq "")
  {
    $serverName = Read-Host 'Please enter the vCenter Server FQDN or IP address'
    $VIServer = $serverName

    #Connect to vCenter Server

    Write-Host
    Write-Host "Connecting to vCenter Server..."
    Write-Host
    Connect-VIServer $VIServer
  }

Else {}

#Create a VM report including VM names, Windows computer names (not FQDN/DNS names),
#IPv4 addresses and comments from the Notes field. Sort by VM names.

Write-Host
Write-Host
Write-Host "Building VM report..."
Write-Host

$VMs = Get-VM
$i = 0
$Output = ForEach ($VM in $VMs)

  {
    $i++
    Write-Progress -Activity "Creating VM report" -Status "Status:" -PercentComplete (($i/$VMs.count)*100) 

    "" | select @{Name = "VM Name"; Expression = {$VM.Name.ToLower()}},
    @{Name = "Windows Name"; Expression = {$WinName = $VM.Guest.HostName -Split'\.' $WinName[0]}},
    @{Name = "IP Address"; Expression = {$VM.Guest.IPaddress[0]}},
    @{Name = "Group"; Expression = {$VM.Notes}}
  }

#Set the output file format, location and date.

Write-Host
Write-Host "Creating report file..."
Write-Host

#Save the report and point the file location.

$Day = (Get-Date).Day
$Month = (Get-Date).Month
$Year = (Get-Date).Year
$File = "VM_Report_" + $Day + "." + $Month + "." + $Year + ".csv"
$Output | Sort-Object "VM Name" | Export-CSV -path "D:\$File" -NoTypeInformation

Write-Host
Write-Host "Your report is here: D:\$File"

Thursday 6 November 2014

Can't call method "configuration" on an undefined value at /usr/bin/vicfg-snmp line 248

Configure SNMP on an ESXi 5.5 host through vMA:

I tried to configure SNMP on an ESXi host, and didn't set a port and a community string for the target, so it returned a warning saying that the switch requires at least a community string and optionally a port (I assumed it would set the default port as it's set for the agent). Once the target and community string are set, the show switch returns a strange error. Basically, the target requires a port to be specified as well, but it cannot be corrected by re-setting the target info. Instead, we need to revert the SNMP agent configuration to factory default or set the port in snmp.xml file or recreate the xml file and set the full target info.







Log on to the host through WinSCP and edit /etc/vmware/snmp.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<config><snmpSettings><enable>true</enable><port>161</port><syscontact></syscontact><syslocation></syslocation><EnvEventSource>indications</EnvEventSource><communities>123123</communities><targets>192.168.1.61</targets><engineid>00000063000000a100000000</engineid><loglevel>info</loglevel><authProtocol></authProtocol><privProtocol></privProtocol></snmpSettings></config>

The KBA Cannot enable or test SNMP on a VMware ESXi 5.1 host (2036910) says:

In the targets section, set an IP Address to which the SNMP traps are to be sent. Alternatively, if you do not want an extra traffic on the network, set a loop-back address. 

For example:

<targets>
192.168.1.61@162 123123
</targets>

So, if we now try to add a port and community string to the target, it returns another error:


So we can either reset the agent configuration to factory default with the switch –r, add a port and community string in the xml file, or rename or delete the xml file and configure the agent again:


<?xml version="1.0" encoding="ISO-8859-1"?>
<config><snmpSettings><enable>true</enable><port>161</port><syscontact></syscontact><syslocation></syslocation><EnvEventSource>indications</EnvEventSource><communities>123123</communities><targets>192.168.1.61@162/123123</targets><engineid>00000063000000a100000000</engineid><loglevel>info</loglevel><authProtocol></authProtocol><privProtocol></privProtocol></snmpSettings></config>

 

So the target port number is required when setting an SNMP target.

Wednesday 27 June 2012

VMs showing on 2 storage locations after being migrated between storages

After migrating several virtual machines in vSphere v5.0, they were showing at 2 storage locations, the source and destination one. However, at the source location, the used space was showing as 0.



The VMs migrated successfully and they were up and running without any issues. It turned out that an ISO file was attached to these VMs. Once the file was removed, the old storage disappeared.

Monday 7 May 2012

Reporting on storage used by VMware virtual machines

Here is a very useful freeware tool for creating reports on VMware virtual machines’ storage usage per drive. The tool is called MCS StorageView and is made by Mightycare. It can be downloaded from here.

Download it and run the exe, then connect to the vCenter server (Connect > Login). Once connected, it will start populating the table. To save the report in a csv file, click Export2CSV.


I was after total allocated and used space per drive in order to know how much was used per drive type (e.g. all prod system drives, all test database drives, log drives, apps drives etc). It is easy to organise the list per drives and calculate the used space:


And then get totals for all drives:


If you have multiple environments (prod, dev, test, staging etc), it’s easy to separate the VMs and calculate the totals per environment.

Tuesday 20 December 2011

Migrating VMware vCenter Server 4.1 and Update Manager databases from MS SQL 2005 to MS SQL 2008 R2

Migrating VMware vCenter Server 4.1 and Update Manager databases from MS SQL 2005 to MS SQL 2008 R2:

1. Backup the vCenter, Update Manager and system databases
2. Stop the following services on the vCenter server:
VMware vCenter Update Manager Service
VMware VirtualCenter Management Webservices
VMware VirtualCenter Server
3. Detach the vCenter and Update Manager databases, drop connections
4. Copy the databases and their logs to the new SQL server
5. Create a login for the vCenter account (and for the Update Manager account if it is different from the vCenter account) on the new SQL server
6. On the new SQL server, grant the vCenter account the db_owner permission over the MSDB system database
7. Attach the vCenter and Update Manager databases to the new SQL server
8. On the new SQL server, grant the vCenter account the db_owner permission over the vCenter database and the Update Manager account (if it is different from the vCeneter account) the db_owner permission over the Update Manager database
9. Install Microsoft SQL Server 2008 R2 Native Client (v10.50.1600.1) on the vCenter server. The old client can stay, but if you want to remove it, remove the existing DSN first.
10. Create new DSNs using the new driver

- For vCeneter open: C:\windows\system32\odbcad32.exe (this is 64-bit version) and chose SQL Server Native Client 10.0
Specify the new SQL server as the database server
Make sure the default database is set to the vCenter database
Test the connection

- For Update Manager open: C:\windows\SysWOW64\odbcad32.exe (this is 32-bit version) and chose SQL Server Native Client 10.0
Specify the new SQL server as the database server
Make sure the default database is set to the vCenter database
Test the connection

11. Start the services from the step 2
12. Create the SQL Agent rollup jobs. The scripts are located on the vCenter server in C:\Program Files\VMware\Infrastructure\VirtualCenter Server
13. Set the vCenter account to be the owner of all the vCenter jobs
14. For any issues, check the logs under C:\Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter\Logs


Location of vCenter Server log files
Managing Data Sources
Microsoft® SQL Server® 2008 R2 Feature Pack
Moving the vCenter Server SQL database
Upgrading to ESX 4.1 and vCenter Server 4.1 best practices