I am usually more planned than this, but today I was distracted while on a call and doing some housekeeping on my Hybrid Runbook Workers side by side. I decided to update the Az modules, coz why not.
1 |
Update-Module Az |
That broke all my Runbooks with the following error:
1 |
Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. |
😡
I tried removing the Az module and installed the previous one in the gallery:
1 2 |
Uninstall-Module Az Install-Module Az -RequiredVersion "10.0.0" |
But that didn’t help. I wish I had noted the previous version of the module! Heck, that’s something I should be mindful of going forward. Unlike the Graph, PnP.PowerShell, or ExchangeOnlineManagement modules whose versions I am mindful of, with the Az modules I just update periodically. Never bit me in the a$$ so far.
Luckily I had a second machine I was using as HRW and I know that works fine.
So I did the following on that machine:
1 2 3 |
foreach ($entry in (Get-InstalledModule | Where-Object { $_.Name -match "^Az" })) { "$($entry.Name),$($entry.Version)" | Out-Files .\azlist.txt -Append } |
This outputs the modules and their versions. I am capturing the info for all the Az.* modules as they all depend on each other. Initially I tried just uninstalling the main Az module and installing the specific version of that but it didn’t help. (Could be I was doing something wrong and this roundabout way is not needed).
Then on the broken machine I did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$hashTable = @{} # Cache the existing versions beforehand to speed things up foreach ($module in Get-InstalledModule) { $hashTable[$module.Name] = $module.Version } Get-Content .\azlist.txt | ForEach-Object { $module = ($_ -split ',')[0] $version = ($_ -split ',')[1] Write-Host "Processing $module" $installedVersion = $hashTable[$module] if ($installedVersion -ne $version) { Write-Host "Uninstalling $module" Uninstall-Module -Name $module -Force Write-Host "Installing $module version $version" Install-Module -Name $module -RequiredVersion $version } } |
Took a while but finally it was done. Now the Runbooks are happy.