Functions/Get-InstalledModuleVersion.ps1


function Get-InstalledModuleVersion {
    [CmdletBinding()]
    param (
    )

    $result = @()

    $excludeList = "Az.|Microsoft.Graph.Beta."

    Get-InstalledModule | Where-Object Name -NotMatch $excludeList | ForEach-Object {
        Write-Verbose "$($_.Name) $($_.Version)"
        $foundModule = Find-Module $_.Name -ea 0
        Write-Verbose "$($foundModule.Name) $($foundModule.Version))"
        if ($_.Version -eq $foundModule.Version) {
            $updateNeeded = $false
        } else {
            $updateNeeded = $true
        }
        $obj = [PSCustomObject]@{
            Name           = $_.Name
            CurrentVersion = $_.Version
            NewVersion     = $foundModule.Version
            UpdateNeeded   = $updateNeeded
        }
        $result += $obj
    }

    return $result

}