Finding Old Snapshots – VMware vSphere PowerCLI

July 6th, 2010

Because it’s a pain to check all VM’s for outstanding snapshots from the VI Client, this script is useful for listing any VM’s that have outstanding snapshots and when they were created. Referenced mostly from here [vSphere PowerCLI Blog]


Connect-VIServer vcenter-server.domain.com
$vms = Get-VM
$mybool = $False
foreach ($vm in $vms){
$snap = Get-Snapshot -VM $vm
if ($snap){
$mybool = $True
Write-Host "VM Name: " $vm.Name " Snapshot Name: " $snap.Name " Created: " $snap.Created
}
}
exit

In the above code the $mybool variable is used to keep track if any VM’s have snapshots or not. The purpose of this code was to send an email if any VM’s had snapshots. So, you could replace Write-Host with a string variable and write the output to that then send it via email to alert someone. You can also use the $snap.Size property to determine how big the VM’s snapshots have grown which is a good indicator on how long it will take to commit them back the the parent disk, if that is your aim.

Windows PowerShell Send Email

July 6th, 2010

This is posted in heaps of places online (this post is pretty useful – includes details on message format and attachments), so mainly for my own reference:

$emailFrom = "someone@domain.com"
$emailTo = "someone_else@domain.com"
$subject = "Subject"
$body = "Some text"
$smtpServer = "mail-server.domain.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

Exchange 2007 Message Discovery and Removal Across Mailboxes

June 16th, 2010

Originally found this post on the Technet forums which links to this MS Exchange Team blog from a few years ago.

This cmdlet is great for discovering or removing messages by searching one or many mailboxes. Excellent for removing large messages sent to large distribution groups or virus/spam messages if identified early by the administrator, etc.

A couple of errors that might be returned by this cmdlet are:

[0] [ERROR] Error was found for (SourceMailboxEmailAddress) because: Error occurred in the step: Moving messages. Failed to copy messages to the destination mailbox store with error:
MAPI or an unspecified service provider.
ID no: 00000000-0000-00000000, error code: -1056749164

[0] [ERROR] Error was found for (SourceMailboxEmailAddress) because: Error occurred in the step: Creating target folder in the target mailbox. An unknown error has occurred., error code: -2147221233

These are permissions issues. The account running the command needs to have full permissions to the source mailbox (first error code) and the destination mailbox (second error code). This is explained well here

That said, also take a look at this if you are sure that permissions are set correctly

Active Directory Topology Diagrammer

May 7th, 2010

I may be a bit late in discovering this since it was last published in 2007, but this tool is brilliant. In short, it automatically discovers and diagrams Active Directory domains, OUs, Sites, Exchange organizations, Applications and Servers.

It requires Visio 2003 or 2007 and uses the .NET Framework v2.0 and can be found here

My Favourite Topic (or Yet Another Lesson in Snapshot-ology)

April 29th, 2010

Another snapshot post. Who new snapshots could be this awesome.

Again, the situation is VCB failing to remove the snapshot it took of a VM when the backup job that kicked it off failed (because of lack of disk space in this case).

First, vcbSnapshot was used to try and remove it via the VCB proxy manually. For one reason or another, this failed and a Consolidate Helper- 0 snapshot is left behind. In the VI Client, it will show no snapshots in Snapshot Manager but a check of the VMDK targets show that the VM is indeed pointing to delta disks.

Tried taking a new snapshot manually to confirm the .vmsd file is not corrupt. The chain appeared good. Used:
vmare-cmd .vmx removesnapshots
and received the error:
unable to access file since it is locked

While looking into the problem, found these excellent resources for the undocumented vmkfstools -D switch which dumps file info to /var/log/vmkernel. It can be used to identify the owner of a file lock which could be causing the above error when trying to commit back the snapshot delta files:

http://vi3.org/download/guides/english/vi3/StoppingaVMandReleasingFiles.pdf
http://blog.core-it.com.au/?p=477

In this case, however, I didn’t go through the process – instead took the coward’s way out and used: service mgmt-vmware restart on the host that the VM was running on and then used vmware-cmd to commit the snapshots – worked fine this time.

So, I would expect that if I had used the -D switch on the VMDK’s attached to the VM, the owner would have eventually been the ESX Host Agent which would be locking the file on behalf of the VCB request. Must remember to go through the process next time to find out for sure…