Created
November 28, 2023 13:57
-
-
Save gioxx/190aef77c8eb78e4af3b6b1f650c05a8 to your computer and use it in GitHub Desktop.
Verifica lo stato dei VMware Tools e della Compatibility di tutte le macchine all'interno di un vCenter al quale si è collegati. Vedi l'articolo sul blog: https://go.gioxx.org/checkvmguest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve the status (and the version) of the VMware Tools and the Hardware Version (Compatibility) of all VMs powered on | |
# GSolone, 2023 | |
# Credits | |
# https://communities.vmware.com/t5/VMware-vSphere-Discussions/How-to-check-VMware-Tools-status-of-VM-use-PowerCLI/td-p/2278893 | |
# https://blogs.vmware.com/PowerCLI/2018/09/discovering-vms-with-specific-vmware-tools-versions.html | |
Set-Variable ProgressPreference Continue | |
$arr_VMStats = @() | |
$ProcessedCount = 0 | |
# Creates a variable that contains VMs which are in the PoweredOn state | |
$VMList = Get-VM | Where { $_.PowerState -eq "PoweredOn" } | |
$TotalVM = $VMList.Count | |
# Names of VMs that will not be shutdown or powered off (example: $VMExclusionList = "vm1","vm2","vm3") | |
$VMExclusionList = "" | |
# Loops through the variable an object at a time | |
Foreach ( $VM in $VMList ) { | |
# Checks if the name of the current VM is in the ExclusionList and skips if it is | |
If ( $VMExclusionList -notcontains $VM.Name ) { | |
$ProcessedCount++ | |
$PercentComplete = (($ProcessedCount / $TotalVM) * 100) | |
Write-Progress -Activity "Processing $VM" -Status "$ProcessedCount out of $TotalVM completed ($($PercentComplete.ToString('0.00'))%)" -PercentComplete $PercentComplete | |
# Retrieve the status (and the version) of the VMware Tools and the Hardware Version | |
$arr_VMStats += New-Object -TypeName PSObject -Property $([ordered]@{ | |
VM = $VM.Name | |
# PowerState = $VM.PowerState | |
# OSFullName = $VM.Guest.OSFullName | |
HWVersion = $VM.HardwareVersion | |
ToolsStatus = ($VM | Get-View).Guest.ToolsStatus | |
ToolsVersion = $VM.Guest.ToolsVersion | |
}) | |
} | |
} | |
$arr_VMStats | Sort-Object VM | Out-Host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve the status (and the version) of the VMware Tools and the Hardware Version (Compatibility) of all VMs powered on | |
# GSolone, 2023 | |
# Credits | |
# https://communities.vmware.com/t5/VMware-vSphere-Discussions/How-to-check-VMware-Tools-status-of-VM-use-PowerCLI/td-p/2278893 | |
# https://blogs.vmware.com/PowerCLI/2018/09/discovering-vms-with-specific-vmware-tools-versions.html | |
# Changes: | |
# 18/10/23- Improve: I show what updates there are to be made only if there is at least one within the array. | |
Set-Variable ProgressPreference Continue | |
$arr_VMStats = @() | |
$ProcessedCount = 0 | |
# Creates a variable that contains VMs which are in the PoweredOn state | |
$VMList = Get-VM | Where { $_.PowerState -eq "PoweredOn" } | |
$TotalVM = $VMList.Count | |
# Names of VMs that will not be shutdown or powered off (example: $VMExclusionList = "vm1","vm2","vm3") | |
$VMExclusionList = "" | |
# Loops through the variable an object at a time | |
Foreach ( $VM in $VMList ) { | |
# Checks if the name of the current VM is in the ExclusionList and skips if it is | |
If ( $VMExclusionList -notcontains $VM.Name ) { | |
$ProcessedCount++ | |
$PercentComplete = (($ProcessedCount / $TotalVM) * 100) | |
Write-Progress -Activity "Processing $VM" -Status "$ProcessedCount out of $TotalVM completed ($($PercentComplete.ToString('0.00'))%)" -PercentComplete $PercentComplete | |
# Retrieve the status (and the version) of the VMware Tools and the Hardware Version | |
$arr_VMStats += New-Object -TypeName PSObject -Property $([ordered]@{ | |
VM = $VM.Name | |
# PowerState = $VM.PowerState | |
# OSFullName = $VM.Guest.OSFullName | |
HWVersion = $VM.HardwareVersion | |
ToolsStatus = ($VM | Get-View).Guest.ToolsStatus | |
ToolsVersion = $VM.Guest.ToolsVersion | |
}) | |
} | |
} | |
$arr_VMStats | Sort-Object VM | Out-Host | |
$csvVMfound = @() | |
Import-Csv -Path "$PSScriptRoot\updateVMlist.csv" | Foreach { | |
$VMname = $_.vm | |
$VMfound = $arr_VMStats | Where-Object { $_.VM -eq $VMname } | |
if ($VMfound) { | |
if ($VMfound.ToolsStatus -eq "toolsOld" -or $VMfound.HWVersion -ne "vmx-19") { | |
$csvVMfound += $VMfound | |
} | |
} | |
} | |
if ($csvVMfound.Length -gt 0) { | |
Write-Host "`nSearch updates available in the CSV list ($PSScriptRoot\updateVMlist.csv)" -f "Yellow" | |
$csvVMfound | Sort-Object VM | Out-Host | |
} else { | |
Write-Host "`n✔️ No updates to manage in the CSV list ($PSScriptRoot\updateVMlist.csv)`n" -f "Green" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment