Files
Backup/_NDGOV_WindowsTeam/ITD.Infra-VMware.VirtualMachine/Public/Get-ITDVMwareVMToolsReport.ps1
T
Zack Meier 1d304511b8 update
2026-04-15 15:45:50 -05:00

71 lines
2.4 KiB
PowerShell

<#
.SYNOPSIS
A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
function Get-ITDVMwareVMToolsReport {
[CmdletBinding()]
param (
[string[]]
$VMName,
[ValidateSet("Windows", "RHEL", "Other")]
[string]
$GuestOS
)
begin {
}
process {
If ($PSBoundParameters.ContainsKey('VMName')) {
$AllVMs = Get-VM -Name $VMName | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -ne "placeholderVm" -and $_.Name -notlike "vCLS*" }
}
else {
$AllVMs = Get-VM | Where-Object { $_.ExtensionData.Summary.Config.ManagedBy.Type -ne "placeholderVm" -and $_.Name -notlike "vCLS*" }
}
If ($PSBoundParameters.ContainsKey('GuestOS') ) {
switch ($GuestOS) {
"Windows" {
$AllVMs = $AllVMs | Where-Object { $_.ExtensionData.Guest.GuestId -like "*windows*" }
}
"RHEL" {
$AllVMs = $AllVMs | Where-Object { $_.ExtensionData.Guest.GuestId -like "*rhel*" }
}
"Other" {
$AllVMs = $AllVMs | Where-Object { $_.ExtensionData.Guest.GuestId -notlike "*rhel*" -and $_.ExtensionData.Guest.GuestId -notlike "*windows*" }
}
Default {
Write-Error "Invalid GuestOS specified. Use 'Windows' or 'RHEL'."
return
}
}
}
ForEach ($VM in $AllVMs) {
$obj = [PSCustomObject]@{
Name = $VM.Name;
PowerState = $VM.PowerState;
GuestOS = $VM.ExtensionData.Guest.GuestId;
ToolsVersion = $VM.ExtensionData.Config.Tools.ToolsVersion;
ToolsUpgradePolicy = $VM.ExtensionData.Config.Tools.ToolsUpgradePolicy
}
Write-Output $obj
}
}
end {
}
}