Hi @PRIYANKA S NAIR Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.
I am not sure if there is any out of the box command/query you can execute to achieve this. There is a property called parentScopes which will be a part of the child device twin and will contain a reference to the parent device. Here is the sample of the value the property withholds in the child device twin JSON.
"parentScopes": [
"ms-azure-iot-edge://Parent1-638316034265745064"
]
Parent1
is the device ID of the parent Edge device which can be extracted from the sample response.
You can execute the below query Azure CLI to get the parent scopes from all the child devices which provide you the details of the parent devices
az iot hub query --hub-name <your-IoTHub-name> --query-command "SELECT parentScopes FROM devices WHERE parentScopes != null"
Please make sure to replace the IoT Hub name in the above command
Alternatively, you can add tag on all the parent devices and query upon this tag to fetch the correct results. Here is an example of how you can do that. Find a parent Edge device on the Azure portal and edit the tags section and add a custom tag of your choice. In the example below, I have added a tag with a name isParent
and provided a value true
You can save this tag and repeat the same to other parent devices. After that, run the following command to fetch the parent devices details.
az iot hub query --hub-name <your-IoTHub-nam>--query-command "SELECT deviceId FROM devices WHERE capabilities.iotEdge = true AND tags.isParent = true"
This will give you the deviceId's of all the parent devices. Please also refer to the article Queries for IoT Hub device and module twins to understand how the queries work.
Hope this helps. Please let us know if you have any additional questions.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.