Restore Snapshot to vmdk file – Part 1

With no tools available, i needed to restore a snapshot image to a vmware virtual disk. Normally a bartpe with snapshot integrated and network working is used for this, but this time i did not had access to my bartpe iso file to restore the snapshot image.

What did i do to restore the snapshot image to a vmdk (the vmdk was not partitioned yet)?

Dowloaded vdk and mounted the disk in a command line with:

  1. VDK open 0 Virtualdisk.vmdk /RW
    After answering a few errors with i (ignore), the disk was mounted
  2. Started snapshot and went to the selection process of the restore option
  3. When i reached the option to select the disk, selected the mounted disk
  4. Right click and choose “Create primary Partition” on the mounted disk
  5. Restore the disk image to the mounted disk
  6. Close vdk “vdk close 0”
  7. Start the virtual machine

Used the following site as a reference: http://www.drivesnapshot.de/en/tips.htm

Change all ESX root passwords

Another great script from Arnim van Lieshout.

With this script you can change all ESX root passwords at once:

#
# This script changes the root password on all ESX hosts in the esxservers.txt textfile
# 

# Add VI-toolkit #
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1# Get old root credential
$oldrootPassword = Read-Host “Enter old root password” -AsSecureString
$oldrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$oldrootPassword

# Get new root credential
$newrootPassword = Read-Host “Enter new root password” -AsSecureString
$newrootCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword
$newrootPassword2 = Read-Host “Retype new root password” -AsSecureString
$newrootCredential2 = new-object -typename System.Management.Automation.PSCredential -argumentlist “root”,$newrootPassword2

# Compare passwords
If ($newrootCredential.GetNetworkCredential().Password -ceq $newrootCredential2.GetNetworkCredential().Password) {

 # Create new root account object
 $rootaccount = New-Object VMware.Vim.HostPosixAccountSpec
 $rootaccount.id = “root”
 $rootaccount.password = $newrootCredential.GetNetworkCredential().Password
 $rootaccount.shellAccess = “/bin/bash”

 # Get list of Host servers from textfile to change root password on
 Get-Content esxservers.txt | %{
  Connect-VIServer $_ -User root -Password $oldrootCredential.GetNetworkCredential().Password -ErrorAction SilentlyContinue -ErrorVariable ConnectError | Out-Null
  If ($ConnectError -ne $Null) {
   Write-Host “ERROR: Failed to connect to ESX server:” $_
  }
  Else {
   $si = Get-View ServiceInstance
   $acctMgr = Get-View -Id $si.content.accountManager
   $acctMgr.UpdateUser($rootaccount)
   Write-Host “Root password successfully changed on” $_
      Disconnect-VIServer -Confirm:$False | Out-Null
  }
 }
}
Else {
Write-Host “ERROR: New root passwords do not match. Exiting…”
}

Example esxservers.txt:

esx001.yourdomain.local
esx002.yourdomain.local
esx003.yourdomain.local
esx004.yourdomain.local

Download: [wpdm_file id=9]

VMware ESX Datastore Reports – PowerShell

Using Microsft PowerShell and the VI Toolkit for Windos you can do some nice stuff. When looking for a way to make reports for a customer of my i’ve stumbled upon a few scripts.

All you have to do is to install Microsoft Powershell, VI toolkit for windows and have Office on your machine. When running the powershell script [wpdm_file id=”4″] i get the following output:

Datastore Chart

Contents of datastore.ps1:

if ((Test-Path  REGISTRY::HKEY_CLASSES_ROOT\OWC11.ChartSpace.11) -eq $False)
{
       Write-Host "This script requires Office Web Components to run correctly, please install these from the following website: http://www.microsoft.com/downloads/details.aspx?FamilyId=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en"
       exit
}
connect-VIServer yourserver

$Caption = "Datastore Usage %"

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 4
$c.HasTitle = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-datastore |Sort-Object FreeSpaceMB -Descending | foreach-object {

        $capacitymb = $_.CapacityMB
        $FreeSpaceMB = $_.FreeSpaceMB
        $UsedSpace = $capacitymb - $freespacemb

        $perc = $UsedSpace / $capacitymb * 100

        $categories += $_.Name
        $values += $perc * 1
}

$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\Chart.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)
invoke-item $filename