Public/ps1/Export-ESXPatchOverview.ps1

<#
.Synopsis
    Exports a list of VMHosts with their version and build number to a CSV file.
 
.Description
    The Export-ESXPatchOverview function retrieves version and build number information of all VMHosts from all connected vCenters.
    The function exports the list to a CSV file, which includes the name, manufacturer, version, build, parent cluster or host, model, and processor type of each VMHost.
 
.Parameter OutputPath
    Specifies the path where the CSV file will be saved. This parameter is mandatory.
 
.Example
    Export-ESXPatchOverview -OutputPath "C:\path\to\your\file.csv"
    This example retrieves all VMHosts and exports their details, including version and build numbers, to the specified CSV file.
 
.Notes
    Author: bensiegit
    Version: 1.0.0
 
    Requires that you are connected to a vCenter server with appropriate permissions to retrieve VMHost information.
#>


function Export-ESXPatchOverview {
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
    Param(
        [Parameter(Mandatory = $true)]
        [string]$OutputPath
    )

    if ($PSCmdlet.ShouldProcess("Exporting VMHost data to '$OutputPath'")) {
        try {
            # Retrieve VMHosts from vCenter and select relevant properties
            $vmHosts = Get-VMHost |
                       Select-Object Name, Manufacturer, Version, Build, Parent, Model, ProcessorType

            # Export the data to a CSV file with specified encoding and delimiter
            $vmHosts | Export-Csv -Path $OutputPath -Encoding UTF8 -Delimiter ";" -NoTypeInformation
            Write-Output "Data exported to $OutputPath"
        } catch {
            Write-Error "An error occurred: $_"
        }
    }
}