Copy ResourcePools from 1 Cluster to another …

This is a small scriptlet to copy the ResourcePools (just the ResourcePools no settings or VM’s) of Cluster1 to Cluster2

Connect-VIServer -server VCENTER-IP -User USERNAME -Password PASSWORD

$respools = Get-ResourcePool -Location CLUSTER1

foreach ( $respool in $respools ) {
	Write-Host $respool
	New-ResourcePool -Location CLUSTER2 -Name $respool -Confirm:$false
}

Disconnect-VIServer -Confirm:$false -Force:$true -Server VCENTER-IP

Get VM information as Script node for the Virtualization EcoShell

This script node will open a small window with a drop down menu with all your VM’s listed. Select one and click on OK. The script will collect some information and then display them.

Script node:

if ($global:defaultviservers) {
	#Generated Form Function
	function GenerateForm {
	########################################################################
	# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.7.0
	# Generated On: 25/11/2009 12:55
	# Generated By: IT2000
	########################################################################
	
	#region Import the Assemblies
	[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
	[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
	#endregion
	
	#region Generated Form Objects
	$form1 = New-Object System.Windows.Forms.Form
	$button1 = New-Object System.Windows.Forms.Button
	$label1 = New-Object System.Windows.Forms.Label
	$comboBox1 = New-Object System.Windows.Forms.ComboBox
	$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
	#endregion Generated Form Objects
	
	#----------------------------------------------
	#Generated Event Script Blocks
	#----------------------------------------------
	#Provide Custom Code for events specified in PrimalForms.
	$button1_OnClick= 
	{
	$global:Cluster = $comboBox1.SelectedItem
	$form1.close()
	}
	
	$handler_label2_Click= 
	{
	#TODO: Place custom script here
	
	}
	
	$OnLoadForm_StateCorrection=
	{#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
		
		Foreach ($Cluster in (Get-VM | Sort Name)){
			$comboBox1.items.add($Cluster)
			$comboBox1.SelectedIndex=0
		}
		$Combobox1.visible = $true
		$label1.visible = $true
		$button1.visible = $true
		$form1.Text = "Please select a VM"
	}
	
	#----------------------------------------------
	#region Generated Form Code
	$form1.AutoScaleMode = 0
	$form1.Text = "Please wait loading VM's...."
	$form1.Name = "form1"
	$form1.DataBindings.DefaultDataSourceUpdateMode = 0
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 66
	$System_Drawing_Size.Width = 392
	$form1.ClientSize = $System_Drawing_Size
	$form1.FormBorderStyle = 1
	
	$form1.Controls.Add($InfoLabel)
	
	$button1.TabIndex = 2
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 23
	$System_Drawing_Size.Width = 75
	$button1.Size = $System_Drawing_Size
	$button1.Name = "button1"
	$button1.UseVisualStyleBackColor = $True
	
	$button1.Visible = $False
	$button1.Text = "OK"
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 300
	$System_Drawing_Point.Y = 21
	$button1.Location = $System_Drawing_Point
	
	$button1.DataBindings.DefaultDataSourceUpdateMode = 0
	$button1.add_Click($button1_OnClick)
	
	$form1.Controls.Add($button1)
	
	$label1.TabIndex = 1
	$label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,1)
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 23
	$System_Drawing_Size.Width = 50
	$label1.Size = $System_Drawing_Size
	$label1.Name = "label1"
	$label1.Visible = $False
	$label1.Text = "VM:"
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 8
	$System_Drawing_Point.Y = 26
	$label1.Location = $System_Drawing_Point
	
	$label1.DataBindings.DefaultDataSourceUpdateMode = 0
	
	$form1.Controls.Add($label1)
	
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 64
	$System_Drawing_Point.Y = 21
	$comboBox1.Location = $System_Drawing_Point
	$comboBox1.Visible = $False
	$comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0
	$comboBox1.FormattingEnabled = $True
	$comboBox1.Name = "comboBox1"
	$comboBox1.TabIndex = 0
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 21
	$System_Drawing_Size.Width = 217
	$comboBox1.Size = $System_Drawing_Size
	
	$form1.Controls.Add($comboBox1)
	
	#endregion Generated Form Code
	
	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($OnLoadForm_StateCorrection)
		
	#Show the Form
	$form1.ShowDialog()| Out-Null
	
	} #End Function
	
	#Call the Function
	GenerateForm
	
	Get-VM $global:Cluster | % {
	$vm = Get-View $_.ID
	$vms = "" | Select-Object VMName, Hostname, VMState, TotalCPU, TotalMemory, TotalNics, OverallCpuUsage, MemoryUsage, ToolsStatus, MemoryLimit, MemoryReservation, CPUreservation
	$vms.VMName = $vm.Name
#	$vms.Hostname = $vm.hostname
	$vms.Hostname = Get-VMHost -VM $vm.Name
#	Write-Host $vms.Hostname
	$vms.VMState = $vm.summary.runtime.powerState
	$vms.TotalCPU = $vm.summary.config.numcpu
	$vms.TotalMemory = $vm.summary.config.memorysizemb
	$vms.TotalNics = $vm.summary.config.numEthernetCards
	$vms.OverallCpuUsage = $vm.summary.quickStats.OverallCpuUsage
	$vms.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage
	$vms.ToolsStatus = $vm.guest.toolsstatus
	$vms.MemoryLimit = $vm.resourceconfig.memoryallocation.limit
	$vms.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation
	$vms.CPUreservation = $vm.resourceconfig.cpuallocation.reservation
#	$vms.CPUlimit = $vm.resourceconfig.cpuallocation.limit
	$vms.PSTypeNames.Clear()
	$vms.PSTypeNames.Add('Virtu-al.PowerPack.VMInfo')
	$vms.PSTypeNames.Add('Virtu-al.PowerPack.VM')
	$vms
	}
}
Else {
	[System.Windows.Forms.MessageBox]::Show('You must connect to one or more hosts before you can use this node. Please click on the ''Managed Hosts'' node of the VMware PowerPack, connect to one or more of the servers you have configured there, and then try again.','Connection not established',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null
}

Count VMs ToolsOK | ToolsOld | ToolsNotInstalled

Connect-VIServer -server VCSERVER -User USER -Password PASSWORD

$vms = Get-VM | Sort Name
$on = 0
$toolsOk = 0
$toolsOld = 0
$toolsNotInstalled = 0
foreach ($vm in $vms){
	if ($vm.PowerState -like "PoweredOn"){
		$vmview = $vm | Get-View
		$toolsstatus = $vmview.Guest.ToolsStatus
		$toolsrunningstatus = $vmview.Guest.ToolsRunningStatus
		$toolsversionstatus = $vmview.Guest.ToolsVersionStatus
		$on = $on+1
		if ($toolsstatus -like "toolsOk"){
			$toolsOk = $toolsOk + 1
		}
		if ($toolsstatus -like "toolsOld"){
			$toolsOld = $toolsOld + 1
		}
		if ($toolsstatus -like "toolsNotInstalled"){
			$toolsNotInstalled = $toolsNotInstalled + 1
		}
	}
}
$count = $vms.Count
$off = $count - $on
Write-Host "Total VMs: $count" 
Write-Host "Total powered on: $on"
Write-Host "Total powered off: $off"
Write-Host "ToolsOK: $toolsOk"
Write-Host "ToolsOld: $toolsOld"
Write-Host "ToolsNotInstalled: $toolsNotInstalled"

# DisConnect to Virtual Center
Write-Host "DisConnect from Virtual Center"
Disconnect-VIServer -Server VCSERVER -Confirm:$False

Find VMs with Video Card Memory higher than 30MB

Connect-VIServer -server VCENTER -User USER -Password PASSWORD

$vms = Get-VM
foreach ($vm in $vms) {
	$vmview = $vm | Get-View 
	foreach ($device in $vmview.config.hardware.device)
	{
		if ($device.Key -eq 500){
			$test = $device.DeviceInfo.Summary
			$result = $device.videoRamSizeInKB
			if ($result -cgt 30000){
				$mb = $result/1024
				Write-Host $vm $result $mb
			}
		}
	}
}
Write-Host "Done"

Some helpfull PowerShell functions (working with 60 days trail license)

Variables:

$ServerIP = "YourESXiServerIP"
$SysLog = "YourSyslogServerIP"

Configure Syslog server using Powershell

function syslog {
	$VMHost = Get-VMHost -Name $ServerIP
	Set-VMHostSysLogServer -VMHost $VMHost -SysLogServer $SysLog -SysLogServerPort 514
}

Configure NTP server and restart NTP service

function set-ntp{
	$vmHost = Get-VMHost -Name $ServerIP
	Add-VMHostNtpServer -VMHost $VMHost -NtpServer YourNTPserver1
	Add-VMHostNtpServer -VMHost $VMHost -NtpServer YourNTPserver1
	Get-VmHostService -VMHost $VMHost |Where-Object {$_.key-eq "ntpd"} |Start-VMHostService
}

Create a new vSwitch

function create-vSwitch{
        $vmHost = Get-VMHost -Name $ServerIP
        $vmotion = New-VirtualSwitch -VMHost $vmHost -Name vSwitch1 -Nic vmnic4 -NumPorts 1024
}

we got our first HP DL380G6

Today we got our first HP DL380G6 server with 2x 2,8GHz Intel Nehalem, 72GB RAM and 2x 146GB Disks. I have successfully installed VMware ESXi 4 on this box. After this I have started the configuration. In the next days I’m going to run some test on this box and hopefully get the 2nd HP Dl380G6. I’m currently working on a PowerShell script to auto config a ESXi server. I will post some code snippets asap.

Setup a Windows XP appliance …

Currently I setup a Windows XP appliance which I would like to use for a new way to manage a VMware ESXi plattform. A colleague had this idea to create an interface to manage ESXi free server’s from any kind of CMS.

Some details:

OS: Windows XP
Software: Apache, PHP, Powershell, VMware PowerCLI, JSON for PHP

more details will follow soon …

Count VM’s on ESX host

  • This one-liner will count all VM’s on a ESX host
  • Get-VMHost -Server xxx.xxx.xxx.xxx
    | Select Name,@{N="NumVM";E={($_ |Get-VM -Server xxx.xxx.xxx.xxx
    | where {$_.PowerState -eq "PoweredOn"}).Count}}
    
  • Coding for usage with the VESI:
  • $noConnection = $true
    
    if ($global:vmwareManagedHosts) {
        foreach ($key in @($global:vmwareManagedHosts.Keys)) {
            if (($managedHost = $global:vmwareManagedHosts[$key]) -and ($managedHost.Connected)) {
                $noConnection = $false
    			Get-VMHost -Server $managedHost.connection | Select Name,@{N="NumVM";E={($_ |Get-VM -Server $managedHost.connection | where {$_.PowerState -eq "PoweredOn"}).Count}} | Sort Name
    			}
    	}
    }
    if ($noConnection) {
        [System.Windows.Forms.MessageBox]::Show('You must connect to one or more hosts before you can manage the hosts themselves. Please click on the ''Managed Hosts'' node, connect to one or more of the servers you have configured there, and then try again.','Connection not established',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null
    }