Tag Archives: VMware

VMware

VMware vCenter Database Shrink Script

Whenever you’re using VMware vCenter in conjunction with Microsoft SQL Server Express Edition one day your database will run out of free space and vCenter Service will crash.

In VMware vCenter Server Settings, you can configure a period of time how long to retain old events and tasks in the database. Unfortunately, the cleanup process is a SQL Server Agent Job – remember: the free SQL Server Express Edition does not have an SQL Server Agent Service.

Many of my customers experienced this problem so I decided to write a simple batch script:

osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "cleanup_events_tasks_proc"
osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "DBCC SHRINKDATABASE(N'VCDB' )"
osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "DBCC SHRINKFILE (N'VCDB' , 0, TRUNCATEONLY)"

You just need to modify the parameters, like database server, instance name, user, password e.g. to fit your environment.

Now you can just create a simple Windows Task using the Scheduled Task functionality to run this script periodically.

That’s it – your database won’t be run out of space anymore…

Read More
Featured Programming

Creating VMware Virtual Machines using PowerCLI

During one of my current projects, I needed to create lots of virtual machines on a VMware vSphere 5 environment. These virtual machines were used as Citrix XenApp Worker servers provisioned by Citrix Provisioning Services (PVS). Therefore, we additionally needed to configure a static MAC address on each virtual machine.

For faster deployment and better documentation, I decided to do the word with the VMware Powershell interface called PowerCLI:

http://www.vmware.com/go/powercli


# --------------------------------------------------
# Connect to vCenter Server
# --------------------------------------------------
connect-viserver –server "myVCenter.domain.local"

# --------------------------------------------------
# Create new VMs from Template
# --------------------------------------------------
New-VM -Name NewVM01 -Template W2K8R2_Datacenter_ENU -Datastore "SAN-Datastore-01" -VMHost "esx01.domain.local"
New-VM -Name NewVM02 -Template W2K8R2_Datacenter_ENU -Datastore "SAN-Datastore-01" -VMHost "esx02.domain.local"

# --------------------------------------------------
# Setting DRS Rules to separate NewVM01 and NEWVM02
# --------------------------------------------------
New-DrsRule -Name "Never on the same Host" -Cluster "Production" -Enabled $true -KeepTogether $false -VM "NewVM01", "NewVM02"

# --------------------------------------------------
# Setting static MAC Addresses
# --------------------------------------------------
Get-VM "NewVM01" | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress "00:50:56:1A:00:01" -Confirm:$false
Get-VM "NewVM02" | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress "00:50:56:1A:00:02" -Confirm:$false

Read More