Hi, I would suggest to use Azure Resource Graph for that. It will be faster and easier. Example query to use is :
resources
| where type =~ "microsoft.compute/virtualmachines"
| where properties.storageProfile.osDisk.osType in~ ('Linux','Windows')
| extend patchSettingsObject = iff(properties.storageProfile.osDisk.osType =~ "windows", properties.osProfile.windowsConfiguration.patchSettings, properties.osProfile.linuxConfiguration.patchSettings)
| extend assessMode = tostring(patchSettingsObject.assessmentMode)
| extend periodicAssessment = iff(isnotnull(assessMode) and assessMode =~ "AutomaticByPlatform", "Yes", "No")
Keep in mind that the machine needs to be running otherwise it will give No on periodicAssessment result.
Here is guide on how to use PowerShell with Azure Resource Graph.
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.