A. Mikkelsen
VMware ESX scripts, commands, tools and other nice to know things that will make your virtualization days easier!!!!-
vLogView by Xtravirt
Posted on January 31st, 2010 No commentsvLogView, helps you view and search all LOG files from each of your ESX hosts from a single application.
For more info and the latest download, visit http://xtravirt.com/xd10132

-
Playing with PowerCLI
Posted on January 31st, 2010 8 commentsLast week I attended a Magirus course on administrating you VMware environment using PowerCLI, and below is some of the small scripts I created.
These code sniplets will help you manage your VMware environment and give you some ideas of how powerful the VMware PowerCLI really is.
I’m sure VMware will add even more CMDLETS to the PowerCLI in the feature.
Get the latest PowerCLI here.
A function to load different PSSnapins. Put it in the beginning of all you Powershell scripts, to load the different PSSnapin you need. function LoadSnapin{ param($PSSnapinName) if (!(Get-PSSnapin | where {$_.Name -eq $PSSnapinName})){ Add-pssnapin -name $PSSnapinName } }LoadSnapin -PSSnapinName "VMware.VimAutomation.Core" Clone a VM to template. $VMToClone = "vm_name" $TemplateName = "TemplateName" $Datacenter = "Training" get-vm $VMToClone| stop-vm New-Template -VM $VMToClone -Name $TemplateName -Location $(Get-Datacenter $Datacenter) Convert Template to VM - without changing the name. $TemplateName = "TemplateName" Set-Template -Template $(get-template $TemplateName) -ToVM Convert VM to Template - without changing the name. $VMtoTemplate = "vm_name" $vm = Get-VM $VMtoTemplate | Get-View $vm.MarkAsTemplate() Deploying a VM from template. $strNewVMName = "NewVM_01" $strTemplate = "TemplateName" $strDestinationHost = "ESX01" New-VM -Name $strNewVMName -Template $(get-template $strTemplate) -VMHost $(Get-VMHost $strDestinationHost)
Deploying a VM from template using a Customization Specification and using Thin provisioning. Make sure the CustomSpec has been created beforehand. $strNewVMName = "NewVM_01" $strTemplate = "TemplateName" $strDestinationHost = "ESX01" $strCustomSpec = "TEST-CustomSpec" New-VM -Name $strNewVMName -Template $(get-template $strTemplate) -VMHost $(Get-VMHost $strDestinationHost) -DiskStorageFormat Thin -OSCustomizationSpec $(Get-OSCustomizationSpec $strCustomSpec)Moving a VM to a specific folder. $strDistinationFolder = "MyFolder" $strDatacenter = "Training" $VMToMove = "MyVM" move-vm -VM $(get-vm $VMToMove) -Destination $(Get-Folder -Name $strDistinationFolder -Location $(Get-Datacenter $strDatacenter))
Copying a file to a Windows VM (With or without network access) Requires VMware tools to be running. $VM = get-vm -name "myVM" $target = "C:\MY_DIR\" $source = "C:\MY_DIR\test.txt" Copy-VMGuestFile -Source $source -Destination $target -vm $VM -LocalToGuest -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password" -Force:$trueCopying a file from a Windows VM (With or without network access) Requires VMware tools to be running. $VM = get-vm -name "myVM" $target = "C:\MY_DIR\" $source = "C:\MY_DIR\test.txt" Copy-VMGuestFile -Source $source -Destination $target -vm $VM -GuestToLocal -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password" -Force:$trueListing the content of "C:\Windows\System32" from a VM - remotely $VM = get-vm -name "myVM" Invoke-VMScript -VM $VM -ScriptText "dir" -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password"
Run msinfo32 on a guest VM and pipe the output to a TXT file - Using PowerShell. $VM = get-vm -name "myVM" $script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport.txt"' Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password"
Open the above output file in the guest VM - Using PowerShell. $VM = get-vm -name "myVM" $script = '&"notepad.exe" "$env:Tmp\inforeport.txt"' Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password" -ScriptType Bat
Run msinfo32 on a guest VM and pipe the output to a TXT file - Using batch commands. $VM = get-vm -name "myVM" $script = '&"%programfiles%\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "%tmp%\inforeport.txt"' Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password" -ScriptType Bat
Open the above output file in the guest VM - Using batch commands. $VM = get-vm -name "myVM" $script = '"notepad.exe" "%Tmp%\inforeport.txt"' Invoke-VMScript -VM $VM -ScriptText $script -HostUser "root" -HostPassword "password" -GuestUser "myVM\administrator" -GuestPassword "password" -ScriptType Bat
-
Interpret the output of ESXTOP in vSphere
Posted on January 6th, 2010 No commentsIf you need a good guide to Interpreting the statistic from ESXTOP then take a look at this guide from VMware.
http://communities.vmware.com/docs/DOC-9279
I’m using it to troubleshoot performance issues (poor response times) from clients in different locations, when using the remote console.
-
Restarting management Agent on ESX 3.x
Posted on November 25th, 2009 1 commentRestarting the Management agents on ESX Server 3.x
- Login to the ESX host using SSH (or from COS)
- Type service mgmt-vmware restart.
CAUTION
Before restarting the Management Agent make sure that Automatic Startup/Shutdown is Disabled
For more info see
Restarting hostd (mgmt-vmware) on ESX Server Hosts Restarts Hosted Virtual Machines Where Virtual Machine Startup/Shutdown is Enabled (1003312) - Type service vmware-vpxa restart.
- Exit the SSH session or logout of COS
-
IBM/Lenovo Bios update/Embedded Controller with dead/no battery
Posted on November 24th, 2009 No commentsBelow solution is on you own risk.
- Download the Bios/Embedded Controller from IBM/Lenovo (Diskette version)
- Rename the file UPDTFLSH.EXE to UPDTFLSH.EXE.OLD
- Create a copy of QKFLASH:EXE and rename it to UPDTFLSH.EXE
- Boot the labtop from the diskette
- Follow normal procedure for updating BIOS/Embedded Controller
- DON’T TURN OFF THE PC OR REMOVE POWER
- When the BIOS/Embedded Controller is updated the PC will trun off
- Poweron and enter BIOS (F1) to verify that the new BIOS/Embedded Controller is installed.
-
Upgrading Windows 2008 from virtual HW 4 to 7 may cause problems
Posted on November 23rd, 2009 No commentsJust found this very interesting article http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1013109 describing a problem with Windows 2008 and ESX 4 virtual hardware version 7.
In short the article states that you might have the disks go offline in a Windows 2008 VM if you
- Upgrade virtual hardware from version 4 to 7
- Installing a new VM with virtual hardware 7
There is two ways to get around this (taken from the VMware KB 103109)
————————
This can be resolved by changing the SAN Automount Policy on the system. See the Microsoft article http://support.microsoft.com/kb/973834 to change the SAN Policy to online.The SAN policy is defined within the VDS environment of the system and is represented by the following values:- VDS_SP_UNKNOWN = 0×0
- VDS_SP_ONLINE = 0×1
- VDS_SP_OFFLINE_SHARED = 0×2
- VDS_SP_OFFLINE = 0×3
For more information, see http://msdn.microsoft.com/en-us/library/bb525577(VS.85).aspx.On Windows Server 2008 Enterprise and Windows Server 2008 Datacenter, the default SAN policy is VDS_SP_OFFLINE_SHARED. On all other Windows Server 2008 editions, the default SAN policy is VDS_SP_ONLINE.To query current SAN policy from the command line, start DISKPART and issue a SAN command:C:\>DISKPART.EXE
DISKPART> san
SAN Policy : Offline Shared DISKPART> exitAlternatively, you can set the disk to Online after the hardware version upgrade.To set the disk to Online:- Log in to your system as an Administrator.
- Click Computer Management > Storage > Disk Management.
- Right-click the disk and choose Online.
-
Free virtualization fools
Posted on November 19th, 2009 No commentsDavid Davis has put together a list of what he thinks is some of the best free virtualization tools avaiable.
- VMware vSphere ESXi Free Edition and VMware Go
- VMware vMA, vCLI (or command-line interface), PowerCLI, and scripts from the vGhetto script repository such as vSphereHealthCheck
- Veeam Monitor (free edition), FastSCP, and Business View
- Vizioncore Wastefinder, vConvert SC and Virtualization EcoShell
- SolarWinds’ VM Monitor
- Trilead VM Explorer
- TripWire ConfigCheck
- ConfigureSoft/EMC Compliance Checker
- ESX Manager 2.3 from ESXGuide (ESX 3i and 4i are not supported)
- vKernel SearchMyVM, SnapshotMyVM, and Modeler
- Hyper9 GuessMyOS Plugin, Search Bar Plugin, and Virtualization Mobile Manager
- XtraVirt vAlarm and vLogView
I still think that he is missing a few, like
- Project Onyx (Just released in Alpha)
- ESX HealthScript (ESXi not supported)
- Ultimate Deployment Appliance (UDA)
- Daily ESX Report (Script)
- Syslog Appliance
- PowerGUI VMware Power Pack
- PowerWF Studio
See the full article at
http://searchservervirtualization.techtarget.com -
Project Onyx Alpha Release
Posted on November 18th, 2009 No commentsFinally everyone outside the closed beta is now able to get hands on with the cool application Project Onyx.
Thanks to Carter ShanklinProject overview - Got it from http://www.ntpro.nl/blog/archives/1330-Project-Onyx-Alpha-Release.html
Onyx is a standalone application that serves as a proxy between the vSphere Client and the vCenter Server. It monitors the network communication between them and translates it into an executable PowerShell code. Later, this code can be modified and saved into a reusable function or script.
- To connect to a server, click the “Connect” icon.
- Enter the IP of the vCenter Server on which you want to work and click Connect.
- Connect with any of the following clients:For vSphere Client, in the “IP Address” field enter the following address:
http:// [IP of the machine where Onyx is running] : [listening port]For vSphere PowerCLI, run the following command:
Connect-VIServer [IP of the machine where Onyx is running] -Protocol http
-Port [listening port] -User [username] -Pass [password] - To start the generation of PowerCLI.NET scripts, click the “Start” icon.
- To save the generated script, click the “Save output to file” icon.
You can download Project Onyx Alpha from http://blogs.vmware.com/files/onyx_1.5.3607.25516.zip or http://bit.ly/vmwOnyx15.
To learn how it works please see this video from YouTube.com
-
Another easy guide from Techhead - iSCSI on vSphere
Posted on November 11th, 2009 2 commentsIf you are looking for a easy and simple guide for setting up iSCSI on vSphere (ESX 4.x) you might want to take a look at this guide from www.techhead.co.uk
http://www.techhead.co.uk/vmware-esxi-4-0-vsphere-connecting-to-an-iscsi-storage-target -
Running the vSphere client on Windows 7
Posted on November 10th, 2009 No commentsMany admins have upgraded to Windows 7 and gotten into problems when trying to install the vSphere Client.
I have found a few guides to do a workaround, but the best guide is found at techhead.co.uk.
http://www.techhead.co.uk/running-vmware-vsphere-client-on-windows-7Thanks to Kiwi Si.
-
Extend disk with snapshots - How to fix the error
Posted on October 29th, 2009 No commentsYesterday I by mistake extended a disk on a VM that had snapshots.
Using vmkfstools.
Kind of like this thread (http://communities.vmware.com/thread/238035).
This resulted in the following PowerOn error:
Failed to power on Servername on Host in Cluster:
Cannot open the disk ‘/vmfs/volumes/LUN/Folder/VM.vmdk’
Reason: The parent virtual machine disk has been modified since the child was createdThe server was a database server so I had no choice than to fix it.
I tried the following with no luck:
- Reverting to snapshot didn’t help - (Don’t try this if you don’t have a good backup)
- Shrinking the vmdk again using vmkfstools - (This has not been possible since ESX 3.0)
Then I tried to use VMware Converter to do a V2V and in the first try (all defaults) that didn’t help the VM started with a BSOD.I tried again using the Converter but this time I changed one default parameter.In the “View/Edit Options” tap, remove the check mark in “Reconfigure destination virtual machine” and click YES to the warning.Removing the reconfigure option saved my day.
The VM started and I was able to restore the latest files from backup.
-
Powershell - Add host to Cluster and license it.
Posted on October 5th, 2009 No commentsThis PowerShell script adds a host to a Cluster and licenses it.
Add-PSSnapin VMware.VimAutomation.Core Connect-VIServer "VC_server_name" -User "Administrator" -Password "password" add-vmhost "esxhost" -location (get-datacenter -name 'Datacenter' | get-folder -name 'Folder' | get-cluster -name 'Cluster') -user "root" -password "password" -force: $true $targethostMoRef = (get-VMHost $strHost | get-view).MoRef $si = Get-View ServiceInstance $LicManRef=$si.Content.LicenseManager $LicManView=Get-View $LicManRef $licassman = Get-View $LicManView.LicenseAssignmentManager $licassman.UpdateAssignedLicense($targethostMoRef.value,”YOUR LIC KEY”,”vSphere4 Enterprise Plus (1-12 cores per CPU”) Disconnect-VIServer -Confirm:$falseDownload it here.
-
32-bit ODBC DSN required for vSphere running on 64-bit OS and MSSQL
Posted on September 29th, 2009 2 commentsLast week I upgraded a Virtual Center server from Win2003 & MSSQL 2000 (32-bit) to Win2008 & MSSQL 2005 (64-bit).
During the installation of vCenter it asked for a 32-bit ODBC even though all the new systems was running 64-bit.
After a some time on Google i found that Windows 64-bit also includes a 32-bit version of the ODBC.To set up a 32-bit DSN launch the 32-bit version of the Data Source Administrator. It is located at:
%systemdrive%\Windows\SysWoW64\Odbcad32.exeAlso se
http://www.vmwarewolf.com/32-bit-odbc-dsn-for-vsphere/ -
Partitioning you ESX host (vSphere)
Posted on September 28th, 2009 No commentsDuncan Epping has released a great post on how to partition your ESX 4.0 (vSphere) using scripting and the grafical installer
http://www.yellow-bricks.com/2009/05/27/partitioning-your-esx-host-part-ii/
You cannot define the sizes of the /boot, vmkcore, and /vmfs partitions when you use the graphical or text installation modes. You can define these partition sizes when you do a scripted installation.
The ESX boot disk requires 1.25GB of free space and includes the /boot and vmkcore partitions. The /boot partition alone requires 1100MB.
The vmcore is created automatically by the installer
Primary:
/ - 5120MB
Swap - 1600MB
Extended Partition:
/var - 4096MB
/home - 2048MB
/opt - 2048MB
/tmp - 2048MB -
Quick guide for upgrading VirtualCenter database from MSSQL2000 to MSSQL2005
Posted on September 25th, 2009 No commentsToday when I needed to upgrade my VC database from MSSQL2000 to MSSQL 2005 i came upon these quick guides.
-
Howto add webages in vCenter
Posted on September 23rd, 2009 No commentsIf you want to add a website tab to your vCenter, then here is a quick way to do it.
http://www.ntpro.nl/blog/archives/1270-vSphere-Plugin-Wizard-Released.html
Thanks to Ricky over at virtualizeplanet.com
-
Ever wondered it you ESX servers are hardened enough
Posted on September 17th, 2009 No commentsHave you ever needed to document how secure your ESX servers are.
If the answer is yes then take a look at these free fools (Compliance Checkers) from ConfigureSoft.com.
http://www.configuresoft.com/compliance-checker.aspxIf the answer is no I would sugest you took a look at the tools anyway……
Compliance Checker for VMware ESX, checks the compliance of VMware ESX hosts against VMware hardening guidelines and Center for Internet Security (CIS) benchmarks.
Compliance Checker for PCI DSS, checks the compliance of servers and desktops against PCI DSS v1.2 requirements as specified by PCI Security Standards Council.
-
A must have for anyone using PowerShell to control VMware
Posted on September 17th, 2009 No commentsVMware have released a demo on YouTube that shows a “must have” for PowerShell users who automate and manage vSphere and vCenter through PowerShell.
The project is named “Onyx” and works like a middelware between the vCenter Client and the vCenter Server.
Onyx is unfortunately still in a private beta and therefore not acceble to the Public……..
Read more on rtfm-ed.co.uk.
http://www.rtfm-ed.co.uk/?p=1643Or read more on the “get-scripting podcast” blog
http://get-scripting.blogspot.com/2009/08/get-scripting-podcast-episode-12-carter.htmlESX, ESXi, PowerShell, Scripting, Tools, Virtual Center automating, esx, esxi, onyx, PowerShell, script, sdk, vmware, vsphere -
Scripts to document your vSphere enviroment
Posted on September 16th, 2009 1 commenthttp://communities.vmware.com/message/1286580#1286580
http://www.ivobeerens.nl/?p=256
http://www.configuresoft.com/esx-compliance-checker.aspx
http://www.vmware.com/support/developer/vima/
http://www.run-virtual.com/?p=233 (VMware CPU Host Info)
http://teckinfo.blogspot.com/2009/01/vdiagram-document-your-vi-with-one.html (vDiagram)
-
VCP vSphere (VCP410) practice exam
Posted on September 16th, 2009 3 commentsSimon Long has posted a great test exam for the VCP410 exam.
I used it to study for mine.
http://www.simonlong.co.uk/blog/vcp-vsphere-4-practice-exam/Also take a look at Somins study notes.
http://www.simonlong.co.uk/blog/vcdx-study-notes/Another great and very usefull help is to use and memorize the vReference Card.
http://www.vreference.com/Thanks to VCP for the below study sites
http://www.passguide.com/vcp-410.html
http://www.vcp-410.comAnd not to forget Scott Vessey who created a great collection of resources for studying
http://vmwaretraining.blogspot.com/2009/09/studying-for-vcp-on-vsphere-4.html

