Line 352: As suggested by @B1mbojr1,
ConvertFrom-Json will not recognize the parameter -Depth 9, hence removed it.
Line 317: This was mind-boggling, not sure who removed the 'Count' property from "Get-MgDeviceManagementManagedDevice", tried different ways included 'adding | measure in a different variable', the most seamless way to resolve this would be to save the $IntuneDevices as an array so the 'Count' property would be recognized in the rest of the script, otherwise the batch mode and success message with $Intunedevices.count fails.