Thursday, October 28, 2010

VMware script to delete/remove VMs, guests

I have to admit since I started playing with PowerCLI I’ve been enjoying it more and more.

A few weeks ago I needed to delete 50 VMs from the environment and I realized I would give the script a shot.
Of course I could do that through Virtual Center, but it would take some time to do it manually.

So, here’s my script which deleted all the 50 VMs in about 08 minutes ; )

Assuming that you have a txt file with your guest’s name one per line.
Mine was c:\temp\servers.txt (replace this on the script for you file name)

Open PowerCLI
Connect on VC: Connect-VIServer –Server “your_VC_goes_here”
Get-Content c:\temp\servers.txt | foreach { Remove-vm $_ -DeleteFromDisk -Confirm:$false }

Have a good one

Wednesday, October 20, 2010

Managing Vmware Snapshots – 3/3

Now that you did a clean up on your environment…. You still don’t know what I’m talking about….. check the previous post.

Next time you don’t what to be surprised with the number of guests running with snapshots on your environment, so the perfect approach would you be notified when they are creating them, right ? Now with vSphere 4.x it’s possible.

Just creates an alarm that will trigger when a snapshot is created.

Check this vmware KB about how to do that..

Thursday, October 14, 2010

Managing Vmware Snapshots – 2/3

Now that you understand what’s snapshot and when to use it…what... you don’t know ?!?! check my previous post about it…

So, you are probably wondering what VM on your environment has snapshots, how long they have been there, but if you are like me, that have hundreds of guests on your environment, using snapshot manager is not the best tool for the job.

VMware provides a Windows PowerShell interface to vSphere functionality. The products below offer PowerShell cmdlets for administering vSphere components. With PowerCLI you can create script to help you with several tasks on your environment.

First you need to install PowerCLI, download it here. (I’m assuming you already have PowerShell on your workstation.

Here’s the steps to get a list of VMs with snapshot

- launch vSphere PowerCLI
- connect on your VC. Run: Connect-VIServer –Server “your_VC”
- run: Get-VM | Sort Name | Get-Snapshot | Select VM,Name,Description,Created

there will go:
If you want to export it to CSV file just run:

Get-VM | Sort Name | Get-Snapshot | Select VM,Name,Description,Created | Export-CSV "Your_File_outup"

It’s time for the cleanup …

Wednesday, October 6, 2010

Managing Vmware Snapshots – 1/3

I’ll write a serie of 3 posts talking about the snapshots.

The first one (this one), will cover the fundamental of snapshots, best practices and when to use it.
The second one, will cover how to extract a list of guests with snapshots from your environment
The last one, will cover how to monitor the creation of the snapshots.

Let’s start…

What’s VMWARE snapshot ?
A snapshot is a picture of your system at the time the snapshot is taken. When you create a snapshot, a new DELTA file is create to store the changes that have occurred to the virtual machine since the snapshot was taken.

If you want to know more about snapshots, VMWARE has a good KB about it.

If you dont know how to create snapshots, check the video bellow

Vmware Snapshots Best practices

• Snapshots are not backups. As the snapshot file is only a change log of the original virtual disk, do not rely upon it as a direct backup process.
• The maximum supported amount in a chain is 32. However, VMware recommends that you use only 2-3 snapshots in a chain.
• Use no single snapshot for more than 24-72 hours.
• Confirm that there no snapshots present before a Storage vMotion.
• Confirm that there are no snapshots present (via command line) before increasing the size of any Virtual Machine virtual disk or virtual RDM.

Issues with Snapshots

• Old snapshots could grow so large as to cause issues when deleting/committing them to the original virtual machine disks.
• These snapshots can very quickly grow in size, filling datastore space.
• An excessive number of snapshots in a chain or snapshots large in size may cause decreased virtual machine and host performance.
• Migrating an ESX 3.x virtual machine with snapshots in powered-off or suspended state to another datastore might cause data loss and make the virtual machine unusable
• Increasing the size of a disk with snapshots present can lead to corruption of the snapshots and potential data loss.

So, when to use snapshots anyway

Snapshots are very good for testing new functionalities, installing new applications, patches, changing applications, in fact for every change you would make on the system that could take the system to fail. It’s a very fast recovery process, you just take an snapshot before you make any change , do you thing and if something goes wrong you can undo it very fast.
But remember, Commit snapshots on these virtual machines as soon as you have verified the proper working state of the process you are testing.|

Friday, October 1, 2010

How to identify a non-aligned disk - VMWARE

I few months ago I wrote an article about misalignment disk and the performance issues it could bring to your environment… remember it here.

Now that you understand the disk alignment it’s time to check your environment and see how big the issue on your environment is.

Vizioncore has a good tool for the job vOptimizer !!

You can download a free tool that will scan your environment and tell you which guest is not 64k aligned. It’s called vOptimizer Waster Finder and you can download it from here.

Here’s also a good presentation about the product.

It also brings some cool reports. Here's an exaample of the disk alingment report.

You will probably notice a product called vOptimizer Pro, ok, that’s the paid version; it does a lot of other cool tricks, like resizing the disks and make the correct alignment of the disk.

But how to make a disk aligned is a subject for another topic….

Who am I

My photo
I’m an IT specialist with over 15 years of experience, working from IT infrastructure to management products, troubleshooting and project management skills from medium to large environments. Nowadays I'm working for VMware as a Consulting Architect, helping customers to embrace the Cloud Era and make them successfully on their journey. Despite the fact I'm a VMware employee these postings reflect my own opinion and do not represents VMware's position, strategies or opinions. Reach me at @dumeirell

Most Viewed Posts

Blog Archive