@Pankaj Joshi Thanks for your question. For your requirement, its suggested to use Azure Policy. Whether it's possible to identify the agent that is installed within the virtual machine or not, it needs to be verified within PowerShell script.
For using automation to verify, you need to retrieve all the virtual machines and individually verify whether the extension are installed or not. Here are PowerShell commands that will help you achieve your requirement.
- https://learn.microsoft.com/en-us/powershell/module/az.compute/set-azvmextension?view=azps-10.0.0
- https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azvm?view=azps-10.0.0
For more information, refer this document.