Private/Get-RequiredVcRedistUpdatesFromIntune.ps1
|
function Get-RequiredVcRedistUpdatesFromIntune { <# .SYNOPSIS Determines which Visual C++ Redistributable applications in Intune require an update based on a provided VcList. .DESCRIPTION The Get-RequiredVcRedistUpdatesFromIntune function compares the versions of Microsoft Visual C++ Redistributable Win32 applications currently present in Intune with those specified in a provided VcList object. It outputs objects indicating whether an update is required for each matched application. .PARAMETER VcList A PSObject containing a list of Visual C++ Redistributable packages, typically generated by Save-VcRedist. Each object in the list should include at least 'PackageId' and 'Version' properties. .INPUTS System.Management.Automation.PSObject Accepts a VcList object from the pipeline. .OUTPUTS PSCustomObject Outputs an object for each matched application with the following properties: - AppId: The Intune application ID. - IntuneVersion: The version currently in Intune. - UpdateVersion: The version available in the VcList. - UpdateRequired: Boolean indicating if an update is required. .EXAMPLE $vcList = Save-VcRedist Get-RequiredVcRedistUpdatesFromIntune -VcList $vcList Compares the Visual C++ Redistributable applications in Intune with those in $vcList and outputs which require updates. .NOTES Requires the Get-IntuneWin32App cmdlet to retrieve Win32 applications from Intune. Only applications with notes containing a 'Guid' property matching a VcList PackageId are considered. #> [CmdletBinding(SupportsShouldProcess = $false)] param ( [Parameter( Mandatory = $true, Position = 0, ValueFromPipeline, HelpMessage = "Pass a VcList object from Save-VcRedist.")] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSObject] $VcList ) process { foreach ($Redist in $VcList) { $ExistingIntuneApps = Get-VcRedistAppsFromIntune -VcList $Redist foreach ($Application in $ExistingIntuneApps) { $IntuneVersion = $null if (-not [System.Version]::TryParse([System.String]$Application.displayVersion, [ref]$IntuneVersion)) { throw [System.IO.InvalidDataException]::New("Intune application '$($Application.displayName)' has an invalid display version: '$($Application.displayVersion)'.") } $Update = [System.Version]$Redist.Version -gt $IntuneVersion if ($Update) { Write-Verbose -Message "Update required for $($Application.displayName): $($Redist.Version) > $($Application.displayVersion)." } $Object = [PSCustomObject]@{ "AppId" = $Application.Id "IntuneVersion" = $Application.displayVersion "UpdateVersion" = $Redist.Version "UpdateRequired" = $Update } Write-Output -InputObject $Object } } } } |