A. Mikkelsen VMware ESX scripts, commands, tools and other nice to know things that will make your virtualization days easier!!!!

Friday, December 12, 2008

Copy to and run any file from your host to all VM’s in a single script

Filed under: Scripting,Tools — Tags: , , , — A. Mikkelsen @ 20:57 pm

Today i came across a post on Yellowbricks.com about the VIX API.

Duncan writes about how he was able to copy a file (vb script) from his labtop to all his VM’s in a single script, and then execute the script on all VM’s from the same script – and much much more.
Read more

This got me thinking, the possebilities are endless 😉

  • Install MSI packages in your VM without the use of SMS.
  • Start/stop services based om a script or other thinks.
  • Copy a file to/from a VM to the host that executes the script – like config or log files.
  • etc….

The VIX API run not only on ESX but also on Workstation and Server versions.

So now i just have to find the time to get cracking on some code…..

Friday, December 5, 2008

Lost permissions to a folder in VC

Filed under: vRanger,White Papers — Tags: , , , , , , — A. Mikkelsen @ 10:16 am

Yesterday I by mistake added the VirtualCenter servers local Users group to a folder in VC with ReadOnly permissions.

This resulted in that I couldn’t delete or change any permissions on the folder.

To solve the problem do the following (On a MSSQL2000 – should be almost the same on MSSQL2005):

  • Open the SQL Server Enterprice Manager and browse to the VC_DB (or what you have called the VC database)
  • Locate the table VPX_ACCESS and right click it and choose Open Table -> Return all rows
  • In the buttom of the table you should be able to locate the wrong permissions entery – make a note of the ID.
    If you can’t find the user/group, you can browse the VPX_ENTITY table to locate ENTITY_ID you need.
  • Open the SQL Query Analyzer an choose the VC database
  • To delete the row that contains the wrong permissions run the below SQL code or modify it for you liking.
    To only delete row 221 from the table

    DELETE FROM esx.VPX_ACCESS WHERE ID = 211

    To delete all rows containing a specific user/group from the table

    DELETE FROM esx.VPX_ACCESS WHERE PRINCIPAL = 'your_user or group'

After you have deleted or updated all the permissions you need, you have to restart the VC server service before the changes will take effect.

Disclamer…..
All changes to the VC database should be avoided at all time.
Always make a backup of the database before making ANY changes to it.
All changes to the VC database using examples on this website is at your own risk.

Monday, December 1, 2008

BULK upgrading VM’s memory

Filed under: ESXi,PowerShell,Scripting,vSphere (ESX) — Tags: , , , , , , , , , , — A. Mikkelsen @ 17:34 pm

Today I had to upgrade all our Jumphost VM’s from 256MB to 512MB of memory (more than 200 VM’s).
There are two ways accomplice this.

1. Do it manually (Very time consuming)

2. Script it with PowerShell

As the lazy person I am I decided that scripting was the way forward.
The script I came up with is as follows:

Connect-VIServer "vi_servername" -User "vi_username" -Password password"

# Select all VM's that have less than 512MB and change the Memory to 512MB
foreach ($vm in Get-VM | Select Name,MemoryMB | Where-Object{$_.MemoryMB -lt "512"}){
Set-VM $vm.Name -MemoryMB "512" -Confirm:$FALSE
}

To suppress the script to prompt for acceptance each time I added the following option
-Confirm:$FALSE

The script easily be changed to add or update other VM hardware settings.
– Number of CPU’s (Set-VM <vm-name> -NumCpu 2)

– Rename VM (Set-VM <vm-name> -Name “NewName”)

Find more options and ideas in the “Automating VMware with PowerShell – Hands-On Lab” from VMworls 2008.

Just remember if a VM is running you have to poweroff or shutdown the VM before the changes will take effect.
This is because a restart or reset does’t reload the vmx file.

Update:

The script is now updates so it also implements the following settings

  • Sets Memory Reservation to half of the amount of ram.
  • Sets Memory Limit to “Unlimited”
  • Sets the VM to check for new VMware Tools on PowerOn.
  • Sets the VM to sync time from host.

Take a look at the scripts here.

Powered by WordPress