#***********************************************************************# # # # Script: Upgrade VMware Tools V2 # # Purpose: Scan all guests for tools version and determine upgrade # # # #***********************************************************************# # 3 Nov 2010 - Author: Marco Baars # #***********************************************************************# add-pssnapin VMware.VimAutomation.Core [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') # Load assembly needed for the confirmation dialog cls # Configure these settings to your needs !!!!! $VIserver = "cyg7053" # Adjust this to your VC server name # Connect VC Server Connect-VIServer $VIserver # Open Excel for logging # Required when using Excel 2010 $culture = [System.Globalization.CultureInfo]“en-US” $oldCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture # Open Excel and create new workbook $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $workbook1 = $excel.Workbooks.Add() $ExcelRow = 0 $workbook1.ActiveSheet.columns.item('a').columnWidth = 25 $workbook1.ActiveSheet.columns.item('b').columnWidth = 25 $workbook1.ActiveSheet.columns.item('c').columnWidth = 25 $workbook1.ActiveSheet.columns.item('a').HorizontalAlignment = -4108 $workbook1.ActiveSheet.columns.item('b').HorizontalAlignment = -4108 $workbook1.ActiveSheet.columns.item('c').HorizontalAlignment = -4108 # Get VM's + Tools version $VMarray = Get-VM |Get-View | ForEach-Object { $_ ` | Add-Member -MemberType NoteProperty -Name ToolsStatus -Value $_.Guest.ToolsStatus -PassThru ` | Add-Member -MemberType NoteProperty -Name ToolsVersion -Value $_.Guest.ToolsVersion -PassThru ` } | Sort-Object Name foreach ($item in $VMarray) { if ($item.ToolsStatus -eq "ToolsOld") { $result1 = [Microsoft.VisualBasic.Interaction]::MsgBox("Upgrade VMware Tools on " + $item.Name + " ?", 'YesNoCancel,Question',"Respond please") switch ($result1) { 'Yes' { $result2 = [Microsoft.VisualBasic.Interaction]::MsgBox("Reboot " + $item.Name + " after upgrade ?", 'YesNo,Question',"Respond please") switch ($result2) { 'Yes' { Write-Host "Start upgrade on " $item.Name " Current tools version: " $item.ToolsVersion Write-Host "Server will be rebooted !!!" Update-Tools $item.name $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= $item.ToolsVersion $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Upgraded to " + $ToolsVersion + " with reboot" } 'No' { Write-Host "Start upgrade on " $item.Name " Current tools version: " $item.ToolsVersion Write-Host "Reboot will be postponed, don't forget to do this yourself !!!" update-Tools $item.Name -NoReboot $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= $item.ToolsVersion $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Upgraded, reboot required" $workbook1.ActiveSheet.Cells.Item($ExcelRow,3).Font.ColorIndex=3 } } } 'No' { Write-Host $item.Name not upgraded $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= $item.ToolsVersion $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Not upgraded" $workbook1.ActiveSheet.Cells.Item($ExcelRow,3).Font.ColorIndex=3 $workbook1.ActiveSheet.columns.item('a').Autofit } 'Cancel' { Write-Host "Canceling script ..." $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= $item.ToolsVersion $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Canceled script !!!" $workbook1.ActiveSheet.Cells.Item($ExcelRow,3).Font.ColorIndex=3 exit } } } elseif($item.ToolsStatus -eq "toolsOk") { $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= $item.ToolsVersion $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Already up to date" } elseif($item.ToolsStatus -eq "toolsNotRunning") { $ExcelRow = $ExcelRow + 1 $workbook1.ActiveSheet.Cells.Item($ExcelRow,1)= $item.Name $workbook1.ActiveSheet.Cells.Item($ExcelRow,2)= "N/A" $workbook1.ActiveSheet.Cells.Item($ExcelRow,3)= "Tools not running" $workbook1.ActiveSheet.Cells.Item($ExcelRow,3).Font.ColorIndex=3 } } $workBook1.EntireColumn.AutoFit() $workbook1.ActiveSheet.EntireColumn.Autofit() [Microsoft.VisualBasic.Interaction]::MsgBox("Upgrade script is finished !")
Last Updated (Tuesday, 29 November 2011 11:28)