Exporting VMs MAC and IP from vCenter

I stumbled across a forum post that describes a simple way to export all of your VMs MAC and ip addresses.

Just connect to your vCenter database using SQL Management studio and run the following:

select e.name, n.mac_address, n.network_name, i.ip_address
from vpx_vm v

inner join vpx_nic n on (v.id = n.entity_id)
inner join vpx_entity e on (v.id = e.id)
inner join vpx_ip_address i on (i.entity_id = n.entity_id and i.device_id = n.device_id)

Source: http://communities.vmware.com/thread/217326

Linked: eagerZeroedThick powershell script

I found this great Powershell script that convert virtual disk files to eagered zeroed.

Awesome script! I had to make some changes to make it work in my environment.

 function Set-EagerZeroThick{
 param($vcName, $vmName, $hdName)

# Find ESX host for VM
 $vmImpl = Get-VM $vmName
 Write-Host $vmImpl
 if($vmImpl.PowerState -ne "PoweredOff"){
 Write-Host "Guest must be powered off to use this script !" -ForegroundColor red
 return $false
 }

 $vm = $vmImpl | Get-View
 Write-Host $vm
 $esxName = (Get-View $vm.Runtime.Host).Name
 Write-Host $esxName
# Find datastore path
 $dev = $vm.Config.Hardware.Device[10] | where {$_.DeviceInfo.Label -eq $hdName}
 Write-Host $dev
 if($dev.Backing.thinProvisioned){
 return $false
 }
 $hdPath = $dev.Backing.FileName
 Write-Host $hdPath

# For Virtual Disk Manager we need to connect to the ESX server
 $esxHost = Connect-VIServer -Server $esxName -User $esxAccount -Password $esxPasswd

# Convert HD
 $vDiskMgr = Get-View -Id (Get-View ServiceInstance -Server $esxHost).Content.VirtualDiskManager
 Write-Host $vDiskMgr
 $dc = Get-Datacenter -Server $esxHost | Get-View
 Write-Host $dc
 $taskMoRef = $vDiskMgr.EagerZeroVirtualDisk_Task($hdPath, $dc.MoRef)
 Write-Host $taskMoRef
 $task = Get-View $taskMoRef
 Write-Host $task
 while("running","queued" -contains $task.Info.State){
 $task.UpdateViewData("Info")
 }

 Disconnect-VIServer -Server $esxHost -Confirm:$false

# Connect to the vCenter
 Connect-VIServer -Server $vcName
 if($task.Info.State -eq "success"){
 return $true
 }
 else{
 return $false
 }
}

$vmName = "vm1"
$vCenter = "vcenter_server"
$esxAccount = "rootuser"
$esxPasswd = "password"

Set-EagerZeroThick $vCenter $vmName "Hard disk 1"

To validate before and after running the eageredZeroed script I run the following script:

$vm = Get-VM vm1 | Get-View
$vm.config.Hardware.Device[10].backing
$vm.config.Hardware.Device[10].DeviceInfo

Source: http://www.lucd.info/2009/11/15/scripts-for-yellow-bricks-advise-thin-provisioning-alarm-eagerzeroedthick/

Linked: Move-Template

A couple of days ago I found a really great PowerCLI script that move templates i vSphere. Awesome post and script by afokkema at ict-freak.nl!

Storage vMotion is a great feature to Move your VMs to other datastores. But what if you want to move your Templates?
In the current version of vSphere there is no option within the Client

function Move-Template{
    param( [string] $template, [string] $esx, [string] $datastore)

    if($template -eq ""){Write-Host "Enter a Template name"}
    if($esx -eq ""){Write-Host "Enter an ESX hostname"}
    if($esx -ne "" -and $datastore -eq ""){$vmotion = $true}
    if($datastore -ne ""){$svmotion = $true}

    Write-Host "Converting $template to VM"
    $vm = Set-Template -Template (Get-Template $template) -ToVM 

    if($svmotion){
        Write-Host "Migrate $template to $esx and $datastore"
        Move-VM -VM (Get-VM $vm) -Destination (Get-VMHost $esx) `
        -Datastore (Get-Datastore $datastore) -Confirm:$false
        (Get-VM $vm | Get-View).MarkAsTemplate() | Out-Null
    }        

    if($vmotion){
        Write-Host "Migrate $template to $esx"
        Move-VM -VM $vm -Destination (Get-VMHost $esx) -Confirm:$false
        ($vm | Get-View).MarkAsTemplate() | Out-Null
    }
}

The function above can be used to move a single template via:

Move-Template <template> <esxhost> <datastore>

Source: http://ict-freak.nl/2010/01/21/powercli-move-template/

Linked: VistaSwitcher

I’ve had some issues with application switching, Alt + tab, on my virtual Windows 7 machine. When I pressed alt + tab the Aero-preview pane got stuck. I had to press enter to switch applications.

So I downloaded and installed VistaSwitcher.

Great little app that’s, in my opinion, much better than the original in Windows 7.

How I manually migrated from vCenter 4.0(32-bit) to 4.1u1(64-bit)

Last week I upgraded a vCenter 4.0 installation to 4.1u1. The vCenter was installed on a 32-bit VM so I needed to migrate the installation to a new 64-bit host.

I tried to do the migration according to the vSphere 4.1 upgrade pre-installation requirements and considerations guide. But sadly I got an error during the migration process.

RESTORE FILELIST is terminating abnormally.

The error is described in this thread at vmware communities.

Also, the datamigration scripts makes the original vCenter database corrupt. So if the datamigration fails, as it did for me, the original installation is trashed. (Luckily the datamigration scripts exports a backup before trashing it. But this procedure stinks anyway.)

So how did I migrate? Well I found a workaround and did the following.:

On the old vCenter 4.0 server (32-bit)

  1. Stop the vCenter service
  2. Install Microsoft SQL Server Management Studio Express
  3. Open Management Studio and detached the vCenter database.
  4. Copy the database files.
  5. Copy the % ProgramData% \ VMware \ VMware VirtualCenter \ SSL folder.
  6. Shutdown the vCenter VM.

On the new vCenter 4.1u1 server (64-bit)

  1. Install vCenter 4.1u1 with all the default settings. (This installs SQLExpress and the vCenter database)
  2. Uninstall vCenter from add and remove programs. (This does not remove the SQLExpress installation)
  3. Restore the % ProgramData% \ VMware \ VMware VirtualCenter \ SSL
  4. Install Microsoft SQL Server Management Studio Express
  5. Detach the newly installed database and attach the one from the old vCenter server.
  6. Create a ODBC connection to the local SQLExpress server with the old vCenter database.
  7. Install vCenter 4.1u1 and choose existing ODBC connection during the installation. The installer will detect the old vCenter database and upgrade it.

I wonder why VMware don’t recommend this procedure in the first place?

ZoomIt, a great tool for Windows presentations

Last week I cama across a great little Windows application, ZoomIT.

It’s a small, free app that let’s you zoom in and draw on the screen. Simply put: awesome! :)

ZoomIt is screen zoom and annotation tool for technical presentations that include application demonstrations. ZoomIt runs unobtrusively in the tray and activates with customizable hotkeys to zoom in on an area of the screen, move around while zoomed, and draw on the zoomed image. I wrote ZoomIt to fit my specific needs and use it in all my presentations.

ZoomIt works on all versions of Windows and you can use pen input for ZoomIt drawing on tablet PCs.

Download it here.

How to import/export files to/from a Sharepoint server

I found a great way to migrate all your files from a Sharepoint server. I have kind of had it with Sharepoint, at least for small installations. (You can read more about my new setup in How I built a Apache front-end for a Windows Share with SSL and LDAP Authentication)

The problem came up when I wanted to export all the files form the Sharepoint server. My first instinct was to open Sharepoint in Windows Explorer. But it kept throwing me the “your client does not support opening this list with windows explorer” when I tried to open the Sharepoint in Windows Explorer.

I was almost ready to give up when i found SPIEFolder. A great little application that did exactly what I wanted. I just downloaded is and ran it on the Sharepoint server, 2 minutes later the Sharepoint was exported.

….If only Microsoft could write tools like this. ;)

Introduction

Allows you to either Import a file system folder (And all files and subfolders) into a SharePoint Document Library, and also export a SharePoint Document Library to the file system for WSS 2.0/SPS2003 or WSS 3.0/MOSS 2007. This tool completely replicates the a document libraries folder hierarchy to the file system when exporting, and replicates the folder hierarchy from the file system to the document library when importing.

Importing

The folder can be imported into a Document Library using the following syntax (Note the “import” argument: Example usage:

spiefolder http://krichiemoss "Shared Documents" c:\spiefolder\SeedFiles import

The end result is that the file system folder and complete contents and folder hierarchy is created in the document library on SharePoint

Exporting

To export a SharePoint Document Library to the file system, and replicate it’s folder hierarchy and contents, simply list the sites URL, List Name to read contents from, and File System path to export to. (It is not necessary to supply the optional “export” keyword as it is the default operation.

Example usage:

spiefolder http://krichiemoss "Shared Documents" c:\spiefolder\SeedFiles

This will export the contents of “Shared Documents” to the file system into the folder specified via c:\spiefolder\ and replicate the document libraries folder hierarchy.

Download: http://spiefolder.codeplex.com/

How to backup vCenter running SQL Express

I found a great way to backup the vCenter SQL database running on SQL Express. The downside of running vCenter on SQL Express is the lack of the SQL agent. So running a scheduled backup of the SQL database is a bit tricky.

ExpressMaint is a small application set of scripts/stored procedures that enables you to run backup and maintenance jobs from commandline.(You could run the application ExpressMaint as well, but I installed the stored procedure version.)

I installed and configured it by doing the following:

  1. I created c:\backups to store my backups
  2. I downloaded the ExpressMaint TSQL file.
  3. I opened a new cmd.exe (with administrative rights) and installed the Stored Procedure by running:
    sqlcmd -S .\SQLEXP_VIM -i c:\expressmaint.sql
  4. I created c:\backups\database to store my database backups
  5. I created c:\backups\reports to store my reports
  6. I created c:\backups\backupscript.sql (SQL file that contains the backup settings, note that my script performs the backup and rebuilds the indexes on the vCenter database):
    exec expressmaint
    @database = 'ALL_USER',
    @optype = 'DB',
    @backupfldr = 'c:\backups\databases',
    @reportfldr = 'c:\backups\reports',
    @verify = 1,
    @dbretainunit = 'days',
    @dbretainval = 5,
    @rptretainunit = 'weeks',
    @rptretainval = 1,
    @report = 1
    exec expressmaint
    @database = 'VIM_VCDB',
    @optype = 'REINDEX',
    @reportfldr = 'c:\backups\reports',
    @rptretainunit = 'days',
    @rptretainval = 1,
    @report = 1
  7. I created c:\backups\PerformBackup.cmd (this is the batch script that executes the backup):
    sqlcmd -S .\SQLEXP_VIM -i c:\backups\backupscript.sql
  8. I schedule c:\backups\PerformBackup.cmd using the ordinary Windows scheduled task manager.

How I built a Apache front-end for a Windows Share with SSL and LDAP Authentication

When my company migrated from Exchange 2003 to Exchange 2007 public folder became a big issue. Public folders where used to share documents to our road-warriors. So to fix this we installed a sharepoint server

The problem is that the sharepoint install was like using a rocket propelled grenade to kill a fly. It became more of a problem than a nice way to distribute documents to the people on the road.

So I decided to set up a web-based front-end running apache that points to the windows share that everyone in our office uses.

1. Setting up the virtual machine in our VMware vSphere cluster

OS and SSH

I started by installing a basic Debian 5 server without the GUI stuff. I also installed SSH for remote access..

VMware Tools

I installed VMware tools on the newly created VM.

# apt-get install build-essential
# mount /cdrom
# cp /cdrom/VMware* /tmp
# umount /cdrom
# cd /tmp
# tar xvfz VMware*.gz
# cd vmware-tools-distrib/
# ./vmware-install.pl

2. Webserver

Apache 2.2

I installed apache2.2 by running the following command.

# aptitude install apache2

PHP5

PHP is not actually a part of this setup but I figured that I would install it for future use..

# aptitude install php5 libapache2-mod-php5
# /etc/init.d/apache2 restart

Add support for MySQL in PHP

# aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json
# /etc/init.d/apache2 restart

3. Mount the Windows Share as part of the filesystem.

I mounted the share to the /var/www (to make it simple)..

# apt-get install smbfs 
# update-rc.d -f umountnfs.sh remove
# update-rc.d umountnfs.sh stop 15 0 6 .

I added the following to the fstab: (I have substituted the actual paths and share names with < … >)

//<Windows fileserver>/<Windows share> /var/www/<Windows share> smbfs iocharset=utf8,file_mode=0777,dir_mode=0777,user=<domain>/<username>,password=<password>,gid=33 0 0

To mount the share:

mount -a

4. Security settings

Block access to http://<serverURL>/<Windows share> over port 80 (unencrypted)

I added the following to the /etc/apache2/sites-enabled/000-default

<Directory /var/www/<Windows share> >
Deny from All
</Directory>

Activate support for LDAP authentication in Apache

I created the following symlinks for mod_ldap and mod_authnz_ldap from /etc/apache2/mods-available to mods-enabled

SSL and LDAP authentication

I started by activating SSL by creating a symlink from ssl configuration file (/etc/apache2/sites-available/default-ssl) to the /etc/apache2/sites-enabled directory.

The I made the following changes to the configuration file.

<Directory /var/www/<Windows share> >
    Order deny,allow
    Deny from All
    AuthType Basic
    AuthName "<Name of the share>"
    AuthBasicProvider ldap
    AuthzLDAPAuthoritative on
    AuthLDAPURL ldap://<Windows domaincontroller>:389/dc=<domain>,dc=<local>?sAMAccountName?sub     
    AuthLDAPBindDN "cn=<Bind user that checks the AD>,ou=<some ou with the user>,dc=<domain>,dc=local"
    AuthLDAPBindPassword <password for the binduser>
    Satisfy any
    require valid-user
</Directory>

5. Creating the redirect from http to https

Pretty much every user will open http://<serverURL>/<Windows share> instead of https://<serverURL>/<Windows share>. So I have to create an automatic redirect.

I created the following /var/www/index.php file.

<?php
header( 'Location: https://<serverURL>/<Windows share>');
phpinfo();
?>

6. Nicer looking icons on my index page

I didn’t like the standard Apache index look so I did the following.

# cd /tmp
# apt-get install bzr
# bzr get http://code.ecchi.ca/apache-tango-icons
# ./install.sh

I have also changed the /etc/apache2/mods-enabled/autoindex.conf

IndexIgnore .??* ~* Thumbs.db *.lnk SyncToy_*
IndexStyleSheet "/icons/style.css"

I created/changed the /usr/share/apache2/icons/style.css with the following content.

body {
        font: 85% Arial,Helvetica,Sans-serif;
        color: #444;
        line-height: 2.2em;
        background: #f9f7f5;
}
a:link, a:visited { color: #4265a7; }
.entry a:link, .entry a:visited { font-weight: bold; }
a:hover { color: #993333; }

address {display: none}
table {
border-collapse: collapse;
width: 80%;

}
td, th {
  padding: 2px;
}

References

  1. Debian install ISOs
  2. How to install Apache, mysql etc.
  3. Apache authentication, LDAP etc.
  4. Better lookling icons for the index listing

Linked: Help! My SQL Server Log File is too big!!! | TechRepublic

Great post about shrinking SQL server 2005 log files.

Shrinking the File

Once you have identified your problem and have been able to truncate your log file,  you may need to shrink the file back to a manageable size.  You should avoid shrinking your files on a consistent basis as it can lead to fragmentation issues.  However, if you’ve performed a log truncation and need your log file to be smaller, you’re going to need to shrink your log file.  You can do it through management studio by right clicking the database, selecting All Tasks, Shrink, then choose Database or Files.  If I am using the Management Studio interface, I generally select Files and shrink only the log file.

This can also be done using TSQL.  The following query will find the name of my log file.  I’ll need this to pass to the DBCC SHRINKFILE command.

SELECT name FROM sys.database_files WHERE type_desc = 'LOG'

Once I have my log file name, I can use the DBCC command to shrink the file.  In the following command I try to shrink my log file down to 1GB.

DBCC SHRINKFILE ('SalesHistory_Log', 1000)

Also, make sure that your databases are NOT set to auto-shrink.  Databases that are shrank at continuous intervals can encounter real performance problems.

Help! My SQL Server Log File is too big!!! | TechRepublic.

Export a list of all computers in an AD OU

Today I struggled with the problem of exporting a list of computers in a Windows Domain OU to a simple text file. The purpose of the text file is to act as an input for some other neat scripts.

I stumbled across a post on thebackroomtech.com that made the it seem like a piece of cake.

To export a list of all computers and non domain controller servers in an Active Directory OU, use dsquery.exe.  For example, to export all computers in mydomain.com’s servers OU to machines.txt :

DSQUERY COMPUTER “OU=servers,DC=mydomain,DC=com” -o rdn -limit 1000 > c:\machines.txt

Simple and nice!