List hotfixes using PowerShell in D365FO (AX7)

You probably already know that you can open Visual Studio and from the "Dynamics 365" menu, under "Addins" and "Apply Hotfix", you will find a grid that lists all the hotfixes installed on your environment. The list can be copied and pasted into Excel if you need a better view and you need to filter and search the list. It works, but it could be a bit easier.

In this post I will share a neat function you can use to list installed hotfixes using PowerShell. It inspired by the post from Microsoft Support (Thomas Treen), and I got some help by some of my fellow MVPs to get inspired (shout out to Martin Draab and Lane Swenka).

The function is as follows:

function Get-HotfixList()
{
# Find the correct Package Local Directory (PLD)
$pldPath = "\AOSService\PackagesLocalDirectory"
$packageDirectory = "{0}:$pldPath" -f ('J','K')[$(Test-Path $("K:$pldPath"))]

[array]$Updates = @()

# Get all updates XML
foreach ($packagefile in Get-ChildItem $packageDirectory\*\*\AxUpdate\*.xml)
{
[xml]$xml = Get-Content $packagefile
[string]$KBs = $xml.AxUpdate.KBNumbers.string

# One package may refer many KBs
foreach ($KB in $KBs -split " ")
{
[string]$package = $xml.AxUpdate.Name
$moduleFolder = $packagefile.Directory.Parent

$Updates += [PSCustomObject]@{
Module = $moduleFolder.Parent
Model = $moduleFolder
KB = $KB
Package = $package
Folder = $moduleFolder.FullName
}
}
}
return $Updates
}

With this function, you can list out the hotfixes to a resizable, sortable and searchable grid like this:

Get-HotfixList | Out-GridView


You can list out the hotfixes into a long string where each KB number is separated by a space. Then copy this string into LCS when searching for KBs you want to use in a Hotfix Bundle.

$list = Get-HotfixList | select KB | sort KB
$list = [string]::Join(" ", $list.KB)
$list


Obviously you can use the function to quickly search for a specific hotfix.

Get-HotfixList | where {$_.KB -eq "4055564"}


And one final example, when installing a hotfix bundle, one of the steps are to compile the modules patched, and while you can do a full compile of all modules in the application, you could also just compile only the ones patched. To create a distinct list of modules, run the following statement.

Get-HotfixList | select module | sort module | Get-Unique -AsString


A quick note on the Package Local Directory (PLD) path. In my script I shift between K and J drive. I have only used this script on VMs in the cloud. If you need to run this where the PLD path is on some other drive, you will need to change that in the script.
Related
Recommended