Showing posts with label VI Tool kit. Show all posts
Showing posts with label VI Tool kit. Show all posts

Friday, July 9, 2010

Vmware Project Onyx

VMware Onyx is cool project, it converts mouse click actions to power shell script for automation. I tested with it and found it very useful.

You can download and participate in communities using blow link,

www.vmware.com/go/onyx

Enjoy Scripting!

Saturday, December 19, 2009

VI tool kit - Changing Shares and limit

VI toolkit is a powerful tool. Guess we could do all kind of stuff in VI using it. Below is a simple script which would change the resource settings (ie. shares to normal & limit to unlimited).

clear
#Connect-VIServer localhost
$vm = Get-Cluster "clustername" | get-vm | Get-View
$res = New-Object vmware.Vim.virtualmachineconfigspec
$res.CpuAllocation = New-Object vmware.Vim.ResourceAllocationInfo
$res.CpuAllocation.Shares = New-Object vmware.Vim.SharesInfo
$res.CpuAllocation.Shares.Level = "normal"
$res.CpuAllocation.Limit = "-1"
$res.MemoryAllocation = New-Object vmware.Vim.ResourceAllocationInfo
$res.MemoryAllocation.Shares = New-Object vmware.Vim.SharesInfo
$res.MemoryAllocation.Shares.Level = "normal"
$res.MemoryAllocation.Limit = "-1"
foreach ($v in $vm)
{
$v.reconfigvm_task($res)
}

Thursday, December 3, 2009

Getting Performance report of VM's from VC - VIToolkit

Below is the script to collect the performance report of the VM's mentioned in the specific folder. It uses VI tool kit, exports the average value to excel and sends a mail.

clear
$excel = new-object -comobject excel.application
$excel.visible = $false
$workbook = $excel.workbooks.add()
$sheet = $workbook.WorkSheets.Item(1)
$sheet.cells.item(1,1) = "Hostname"
$sheet.cells.item(1,2) = "CPU AVG"
$sheet.cells.item(1,3) = "MEM AVG"
$sheet.cells.item(1,4) = "Disk AVG"
$sheet.cells.item(1,5) = "NW AVG"
$x = 2
$strpath = "c:\perf.xls"
Connect-VIServer -server
$start = "MM/DD/YY 00:01"
$finish = "MM/DD/YY 23:59"
$vm = Get-VM -Location (Get-Folder "folder")
foreach($v in $vm)
{
$cpuavg = get-stat -Entity $v -Start $start -Finish $finish -Stat cpu.usage.average | `
Measure-Object -Property value -Average
$memavg = get-stat -Entity $v -Start $start -Finish $finish -Stat mem.usage.average |`
Measure-Object -Property value -Average
$diskavg = get-stat -Entity $v -Start $start -Finish $finish -Stat disk.usage.average |`
Measure-Object -Property value -Average
$netavg = get-stat -Entity $v -Start $start -Finish $finish -Stat net.usage.average |`
Measure-Object -Property value -Average
$sheet.cells.item($x,1) = $v.name
$sheet.cells.item($x,2) = $cpuavg.average
$sheet.cells.item($x,3) = $memavg.average
$sheet.cells.item($x,4) = $diskavg.average
$sheet.cells.item($x,5) = $netavg.average
$x++
}
$range = $sheet.usedRange
$range.EntireColumn.AutoFit()
out-null
IF(Test-Path $strPath)
{
Remove-Item $strPath
$Excel.ActiveWorkbook.SaveAs($strPath)
}
ELSE
{
$Excel.ActiveWorkbook.SaveAs($strPath)
}
$excel.quit()
spps -name excel
$filename = “c:\perf.xls”
$smtpServer = “SMTP server”
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “mail@domain.com”
$msg.To.Add(”mail@domain.com”)
$msg.Subject = “”
$msg.Body = “”
$msg.Attachments.Add($att)
$smtp.Send($msg)

Tuesday, December 16, 2008

Finding RDM's

Below is script to find the RDM's in the VM in a given folder,
clear
Connect-VIServer -Server server

$report = @()
$folder = Get-Folder -Name
name
$vms = Get-VM -Location $folder Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or
($dev.Backing.CompatibilityMode -eq "virtualMode")){
$row = "" select VMName, HDDeviceName, HDFileName, HDMode
$row.VMName = $vm.Name
$row.HDDeviceName = $dev.Backing.DeviceName
$row.HDFileName = $dev.Backing.FileName
$row.HDMode = $dev.Backing.CompatibilityMode
$report += $row
}
}
}
}
$report

Creating Multiple VM's from template

Below is a very basic power shell script my first script to create Multiple VM's from template
clear

Connect-VIServer -Server server-User "user" -Password "passwd"
Import-Csv -Path "file" %{New-VM -Template (Get-Template) -VMHost "esxhost" -Name $_.Name -Location (Get-Folder -Name) -Datastore "name_datastore" -network "name_network"