In the future, you may want to be more descriptive in the request than "just give me a script" ....
There's a lot more than just a script, what language are you looking for? Where you do plan on running this script?
I'll throw out an potentially solution as this is a very generic request.
Here is a vSphere SDK for Perl implementation which retrieves all VMs connected to either a vCenter server or ESX/ESXi host and prints out the VM shell name, the hostname if known and the OS type. You will need to use either the vCLI for Linux or Windows or use vMA.
Here's an example output:
[vi-admin@scofield ]$ ./getVM.pl --server esxi4-1.primp-industries.com --username root
vs-manager vs-manager.primp-industries.com Other 2.6x Linux (32-bit)
vShieldB vshieldb.primp-industries.com Other 2.6x Linux (32-bit)
If you're knew to VMware SDK/APIs, you'll want to spend some time going over this document before starting -
If you're interested in getting started with vSphere SDK for Perl, here is a good post that provides some steps with lots of sample code - http://www.virtuallyghetto.com/2010/05/getting-started-with-vsphere-sdk-for.html
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Twitter: @lamw
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Community
If you find this information useful, please award points for "correct" or "helpful".