Category Archives: vmware

Export vCenter Roles

Below is a powershell script to export vCenter roles to a ready to import set of commands.

Script below will not work without using PowerCLI or being connected to vCenter.

$viRolesList = Get-VIRole;
Foreach ( $role in $viRolesList ) {
     $roleName = $role.Name;
     $privilegeSet = $role | Get-VIPrivilege;

     Echo "New-VIRole -Name ""$roleName""" >> vRoles.txt;

     Foreach ( $privilege in $privilegeSet ) {
         $privilegeID = $privilege.ID;
         Echo "Set-VIRole -role ""$roleName"" -AddPrivilege `
         (Get-VIPrivilege -ID $privilegeID)" >> vRoles.txt;
     }
}

Compare VM Name to VM Filename

In case you were blind sided by the vsphere 5.x bug fix that removes the storage vmotion feature that renames the VM’s folder and files. Below is a script that will at least help you identify the VMs that don’t match their file names.

Open powerCLI
Connect to your vcenter

$colorObject = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2";
$vmCluster = Read-Host "Cluster Name";
$vmList = Get-Cluster $vmCluster | Get-VM;
Foreach ( $vm in $vmList ) {
 $vmView = $vm | Get-View;
 $vmView.Config.Files.VmPathName -match "^.*\/(.*)\.vmx$";
 $vmFName = $matches[1];
if ( $vm.Name -match $vmFName ) {
 write-host "$vm matches $vmFName";
 } else {
 write-host "$vm does not match $vmFName" -foreground "red";
 }
}

XenDesktop Catalog Creation Error

After setting up XenDesktop 5.6 with my vSphere 5.0 environment, I received the below error message when trying to create my first catalog.

Environment:

XenDesktop 5.6

ESXi 5.0, vSphere 5.0

Error:

The Catalog has the following errors:
Failed to create the virtual machine; DOMAIN\ComputerName$; Value cannot be null.
Parameter name: source

Solution:

Proper XenDesktop permissions where not applied at the DataCenter level in vCenter.


PowerCLI and Storage

Below are some interesting sets of PowerCLI commands that will give you more information on your VM’s hard drives and your datastores.

The below will give you the total allocated hard drive space of all the VM’s in a cluster.

Get-Cluster "Cluster Name" | get-vm | Get-HardDisk | %{ $vmCapacity += $_.capacityKB }
$vmCapacity

The below will give you the Total Capacity, Free Space, and Usage of your datastores.

Get-Datastore | %{ $datastoreFreeSpace += $_.FreeSpaceMB }
Get-Datastore | %{ $datastoreTotalCapacity += $_.CapacityMB }
$datastoreUsageTotal = $datastoreTotalCapacity - $datastoreFreeSpace

write-host "Total Capacity: $datastoreTotalCapacity MBs"
write-host "Total Free Space: $datastoreFreeSpace MBs"
write-host "Total Usage: $datastoreUsageTotal MBs"


Get Total Space Used by VMs

The other day I was in need of finding out how much space my VMs actually take up.  Below are the commands I used in the vSphere PowerCLI to get that information.

      
$TotalDisk = 0;
#Get Sum of all Disks in TBs
Get-VM | Get-HardDisk | %{$TotalDisk+=[int]$_.CapacityKB}
$TotalDisk = $TotalDisk/1024/1024/1024;
echo "$TotalDisk TBs"


vSphere Resource Allocation and Memory Ballooning

Recently I increased the amount of RAM on a VM, but I forgot to increase the Limit – MB under the Resource Allocation tab on the pool. So my VM had 6144MBs of RAM but was only allowed 4096MBs. Because of this the VM tools on the VM thought that the ESX Host was running low on physical memory and started the ballooning process. This caused the memory usage on the VM to go through the roof, causing the VM to have major issues.

To fix this issue, I set the Limit – MB to the amount of memory I had assigned to the VM and the VM’s memory usage drastically went down.

So to summarize my findings… If the Limit – MB is set lower than the amount of memory the VM has, it can cause ballooning. Also if the VM is getting close to using the set limit then it could cause ballooning.

For more information on vSphere Memory usage, and Memory Ballooning check out the links below.
http://www.vmware.com/files/pdf/perf-vsphere-memory_management.pdf
http://www.vmware.com/pdf/vsphere4/r40/vsp_40_resource_mgmt.pdf


VMWare Workstation 8 on OpenSuse 12.1 64bit

First Download VMware Workstation 8.0.1 from VMWware.

Once downloaded open a terminal and switch to root (be careful)
su –

Change directory to the directory containing the installer

Now change permissions on the installer file so that it is executable
chmod 755 VMware-Workstation-Full-8.0.1-528992.x86_64.bundle

Now execute the installer
./VMware-Workstation-Full-8.0.1-528992.x86_64.bundle

Once the installer finishes install gcc, make, and Kernel-Source
zypper install gcc
zypper install make
zypper install kernel-source

Now open VMWare Workstation 8.0.1
(reboot may be needed)