Disconnect ISO files from Templates with PowerCLI


Just a quick post about how to disconnect ISO files from templates with PowerCLI.  With the following script you can set the CD Drive to No Media. So the ISO files will be disconnected from the Template VMs.

$templates = Get-Template 
foreach($tpl in $templates){
    $vm = Set-Template -Template (Get-Template $tpl) -ToVM 
    Get-CDDrive -VM $vm | Set-CDDrive -NoMedia -Confirm:$false | Out-Null
    ($vm | Get-View).MarkAsTemplate() | Out-Null
}

First the script will fill the templates variable with all the templates available. The next step is to convert the Template back to a VM. When the template is converted to a VM the Get-CDDrive cmdlet is used to set the CD Drive to No Media. When the CD Drive is configured the VM will be converted back to a template. In stead of nine mouse clicks per template you can lean back and drink your cup of coffee or thee and see the magic powered by PowerCLI.

How to copy ISO files between datastores via PowerCLI


We decided to replace our current central ISO datastore to a new one on different storage. You can use the CP commend on the Service Console, if you’re still running ESX classic. But I wanted to investigate if there was a way to do this with PowerCLI. Well there is cmdlet for that called Copy-DatastoreItem. In the PowerCLI help you will find something like this:

Copy-DatastoreItem

Synopsis Copies items between datastores and between a datastore and a local file system provider.

Syntax Copy-DatastoreItem [-Item] [[-Destination]] [-Force] [-PassThru] [-Recurse] [-WhatIf] [-Confirm]

But how do you find the datastore where you want to copy files from?  Well you need to keep in mind the following two objects. The Folder, if you created one (1) and the Datacenter where the Datastore belongs to (2):

image

Now that you know the path to the datastore containing the files you want to copy. You can start PowerCLI and connect to your vCenter server. Before you continue, you need to create a temp directory to temporarily save the ISO files in. In my case this is E:\iso. The one-liner will look like this:

Copy-DatastoreItem vmstore:\Alkmaar\DataCenter\template-01\iso\* E:\iso

And now we wait until the files are copied to the temp directory:

image

The next step is to copy the files from the temp directory to the new datastore.

Copy-DatastoreItem E:\iso\* vmstore:\DataCenter\template-01\iso\

And we wait again:

image

How to return HP Serial Number via iLO and Powershell


Robert van den Nieuwendijk created the basis of this script and shared it on the VMware Communities. The problem I had with the original script was the default SSL certificate which HP uses on the iLO adapters. This resulted in an error and the script failed to return the XML file. So I started a search query on Google and found a post by Paul Brice who had the same problem while getting information via XML on an Iron Port setup. I tried his code to open the iLO XML information and it worked like a charm.

So I updated the script from Robert and added the information from Paul to it. The last thing I changed was the $url and added a RegEx to return the digits from the ESX hostname. For example esx72, the RegEx will return the 72.

Get-VMHost | Where-Object {$_.Manufacturer -eq "HP"} | `
Sort-Object -Property Name | ForEach-Object {
    $VMHost = $_
    $netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
    IF($netAssembly) {
        $bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic"
        $settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")
        $instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @())
        
        if($instance) {
            $bindingFlags = "NonPublic","Instance"
            $useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags)

            if($useUnsafeHeaderParsingField) {
                $useUnsafeHeaderParsingField.SetValue($instance, $true)
            }
        }
    }

    [int]$ip = (([regex]'\d+').matches($vmhost.Name) | select Value).Value

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    $url = "https://192.168.1.$ip/xmldata?item=All"
    $xml = New-Object System.Xml.XmlDocument
    $xml.Load("$url")
        New-Object PSObject -Property  @{
            "Name" = $VMHost.Name
            "Serial Number" = $xml.RIMP.HSI.SBSN
            "ILO Serial Number" = $xml.RIMP.MP.SN
            "ILO Type" = $xml.RIMP.MP.PN
            "ILO Firmware" = $xml.RIMP.MP.FWRI    
          }
} | Export-Csv -NoTypeInformation -UseCulture -Path C:\EsxSerialNumbers.csv 

The output of the script will be exported to a CSV file.

VMware Open Virtualization Format Tool


Download the VMware Open Virtualization Format Tool, formally known as OVF tool here. The documentation can be found here. More info can be fount on the Open Virtualization Format Tool Community.

The OVFTool works quite easy. Just open the VMware OVF Tool directory in a command prompt and run the following command:

ovftool.exe <path to vmx> <path to ovf>

The VM will be converted to OVF:

image

Continue reading “VMware Open Virtualization Format Tool”

Veeam: Instant Recovery stops with status Dismounting…


Today I was investigating an issue with Veeam Backup & Replication Instant Recovery. One of the sessions stopped with the status Dismounting…

image

in the log of this sessions it stops on Removing VM from inventory.

image

The VM was removed from vCenter so why the jobs hangs, I don’t know. So the next thing was to stop and start the Veeam Backup Service. This didn’t help either. So I tried the a System reboot but unfortunately this didn’t work either. So I started to search the Veeam Forums and found a post of someone with the same error. After reading his post I contacted Veeam support and waited for a fix?

First off all before you continue, always contact Veeam support before trying the following solution.

Continue reading “Veeam: Instant Recovery stops with status Dismounting…”

Veeam Backup Academy Certified


Veeam launched the http://backupacademy.com/ website:

Backup Academy is an educational project designed to provide the necessary knowledge you need to become a VM Backup Expert.
You can:

  • – Watch videos to expand your backup knowledge and skills
  • – Pass the Backup Academy Exam
  • – Receive the Backup Academy Certificate

You can also follow the Backup Acedemy on twitter via http://twitter.com/BckpAcademy.

On the Backup Acedemy site you can watch some sessions presented by some of the best guys in the business:

image

And when you think you’re ready to take the exam ,you can take the exam. You have to take 35 questions and I guess the passing score is 75%. So I took the exam during my lunch and 12 minutes later I passed the Exam Smile

image

I think Veeam did a great job by putting this website together with good information and sessions. When you’re working with Veeam Backup and Replication please take a look at http://backupacademy.com/

View Composer: Error during provisioning: Failed to authenticate to AD


Last weekend I was busy with a vCenter migration from vCenter 4.0 on a 32 bit Windows 2003 server to a vCenter 4.1 update 1 server on a Windows 2008 R2 64 bit VM. The database is already running on a separate database server.  The one thing special in this setup was VMware View Composer. So I started the migration and everything went well. vCenter was up and running and VMware View Composer service was started. So it was time to test the provisioning of new Desktops. I changed the pool to deploy 2 new desktops. The process ended with an error:image

I was unable to fix this by myself so I contacted VMware Support and after a while we came up with the following solution: Login to the VMware View Administrator and browse to the vCenter Server page:View Configuration – Servers and select the vCenter server in the the vCenter Servers window and press edit. Now select the Quickprep user for the Desktop pool with the error and press edit:

image

And enter the password for the Quickprep user:

image

After re-entering the password for the Quickprep user, we where ready to test the Desktop pools again. We did a test with an existing Desktop pool and a new pool and both worked as expected. The Desktop pools are working again. I want to thank VMware support for the quick and accurate support.

Veeam: Calculate Destination Storage Needs with Powershell


This post is about how to calculate the storage needs for the configured Veeam Backup Jobs.  When you edit or create a new backup job in Veeam Backup and Replication. You can use the Check Space button to verify if there is enough space to write the backup to disk:

image

But is it possible to get this values via Powershell. The answer is yes. Before you can calculate these values you need to know the formula which Veeam uses to calculate the storage needs. This is the formula:

Backup size = C * (F*Data + R*D*Data)
Replica size = Data + C*R*D*Data

Data = sum of processed VMs size (actually used, not provisioned)
C = average compression/dedupe ratio (depends on too many factors, compression and dedupe can be very high, but we use 50% – worst case)
F = number of full backups in retention policy (1, unless backup mode with periodic fulls is used)
R = number of rollbacks (or increments) according to retention policy (14 by default)
D = average amount of VM disk changes between cycles in percent (we use 10% right now, but will change it to 5% in v5 based on feedback… reportedly for most VMs it is just 1-2%, but active Exchange and SQL can be up to 10-20% due to transaction logs activity – so 5% seems to be good average)

This formula comes from the Veeam Communities: http://www.veeam.com/forums. There is a lot of good information there. So make sure to visit it once in a while Knipogende emoticon.

So now we know the formula, the next step will be to find the data to fill the parameters to calculate the disk space requirements. It’s time to start a script editor to write some Powershell code.  First we start to make sure the Veeam Powershell snapin is loaded:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

The following variables are necessary to calculate the disk space needed to save the job to disk.  First we need to the local disk info so we can return the freespace of the partition where the job will be written to.  The avgcr variable is equal to C in the formula. The numFull variable, well you can guess where that stands for. This variable equals the F in the formula. The retaincycles variable equals the R in the formula. The last variable,

avgdiskchanges equals the D in the formula.

    $diskinfo = Get-WmiObject Win32_logicaldisk
    $options = $vbrjob.GetOptions()
    $avgcr = "50"
    $numFull = $options.FullBackupFrequency
    $retaincycles = $options.RetainCycles
    $avgdiskchanges = "5"

The script that will do the magic:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$DestinationStorage = @()
foreach($vbrjob in (Get-VBRJob | Sort Name)){
    $Details = "" | Select JobName, Driveletter, TotalVMs, TotalCapacityinGB, FreespaceinGB, SourceDatainGB, EstimatedFullBackupSizeinGB, EstimatedRequiredSpaceinGB, StorageNeededinGB
    
    $diskinfo = Get-WmiObject Win32_logicaldisk
    $options = $vbrjob.GetOptions()
    $avgcr = "50"
    $numFull = $options.FullBackupFrequency
    $retaincycles = $options.RetainCycles
    $avgdiskchanges = "5"
    
    $driveLetter = $vbrJob.Info.TargetDir.Split("\")[0]
    $partition = $diskinfo | Where {$_.DeviceID -eq $driveLetter}
    $TotalCapacity = [math]::round($partition.Size / 1GB, 2)
    $FreeSpace = [math]::round($partition.FreeSpace / 1GB, 2)
    $JobSize = [math]::round($vbrjob.Info.IncludedSize / 1GB, 2) #TotalSize in Veeam Console
    $FullBackupSize = $jobSize / 2
    $JobMath = "{0:P0}" -f $avgcr / 100 * ($numFull * $JobSize + $retaincycles * ("{0:P0}" -f $avgdiskchanges / 100 *  $JobSize)) 
    $JobMath2 = [math]::round($JobMath, 2)

    $Details.JobName = $vbrjob.Name
    $Details.Driveletter = $driveLetter 
    $Details.TotalVMs = ($vbrJob.GetObjectsInJob()).Count
    $Details.TotalCapacityinGB = $TotalCapacity
    $Details.FreespaceinGB = $FreeSpace
    $Details.SourceDatainGB = $JobSize
    $Details.EstimatedFullBackupSizeinGB = $FullBackupSize
    $Details.EstimatedRequiredSpaceinGB = $JobMath2 + $JobSize
    $Details.StorageNeededinGB = ($JobMath2 + $JobSize) - $FreeSpace
    $DestinationStorage += $Details
}
$DestinationStorage

And it’s output:

image

I hope you like this script and if you have any questions please leave a comment.

Disk Hard disk # has incorrect changed block tracking configuration


Today another Veeam troubleshooting trick. It’s possible that you’ll receive the following error in one of your Veeam Backup Jobs:

Verifying change block tracking:
Disk “Hard disk 1” has incorrect changed block tracking configuration

This is how it looks like in the Veeam Backup console:

image

The procedure which Veeam describes in the solution for this problem works like this:

  1. Shutdown the VM
  2. VM – Edit Settings – Options – General – Configuration Parameters…
  3. Change every item with ctkEnabled to false
  4. Start the VM
  5. Start the Backup Job to see if this is the solution for this problem.
  6. This is how you change the parameter to false:

image

In my case, the above solution did not solve the problem. So I had to troubleshoot the VM. While checking the configuration a noticed that the Disk was configured with the Independent mode enabled. You can change this setting when the VM is powered off. Go to Hardware, select the Hard disk and disable the checkbox by Independent:

image

The setting above can only be changed when the VM is powered off, if you’re using the vSphere client. It’s also possible to change this setting, on-the-fly with PowerCLI. That rimes Winking smile.

You can run the following one-liner to disable the Independent mode:

Get-VM <vmName> | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} | `
% {Set-HardDisk -HardDisk $_ -Persistence "Persistent" -Confirm:$false} }

Disclaimer: this one-liner worked for me in my environment but test this first because I don’t know exactly what the impact is of this change.

Veeam: Module Snapshot poweron failed. Unable to retrieve the current working directory


After performing an Instant Recovery you might get the following error when the VM is trying to power on:

image

After a quick search on the Veeam Forums I found the following topic: http://www.veeam.com/forums/ about the same issue. In this topic I found the following solution to this issue:


Well, finally i get the issue fixed. I think it could be considered a bug. Let me explain.
If i set “F:\” as a vPower NFS destination, the error shows up. But if i set “F:\any_directory”, then all runs perfect!.
Well i write this here to help anybody with the same issue.

So vPowerNFS cannot be pointed directly to the drive letter of a partition. To change this setting you can use registry editor and your mouse, but you can also run the following Powershell script to change this setting:

$vPowerNFSDir = "D:\vPowerNFS\"

if((Test-Path $vPowerNFSDir) -eq $false){
    New-Item $vPowerNFSDir -type directory
}

If((Get-ItemProperty "HKLM:\Software\VeeaM\Veeam Backup and Replication" -name "NFSDefaultRootPath").NFSDefaultRootPath -ne $vPowerNFSDir){
    Set-ItemProperty "HKLM:\Software\VeeaM\Veeam Backup and Replication" -name "NFSDefaultRootPath" -value $vPowerNFSDir
}

if((Get-Service -DisplayName "Veeam Backup Service").Status -eq "Running"){
    Restart-Service -displayname "Veeam Backup Service"
}

if((Get-Service -DisplayName "Veeam vPower NFS Service").Status -eq "Running"){
    Restart-Service -displayname "Veeam vPower NFS Service"
}

The only thing you have to change in this script is the $vPowerNFSDir variable to the correct location of your Veeam Backup & Recovery Server. This script will check if the folder exists, If this is not the case it will create the folder. The next step is to check the Registry key for the correct location. If this is not the case the script will change the Registry for you. The last step is to restart the Veeam Backup Service and the Veeam vPower NFS Service.

Source: http://www.veeam.com/forums/