
Digital Twin - CLI
Digital Twins are created based on the model definitions. We have already understood how to configure Azure Digital Twin instance. In this chapter, we will explain how to execute simple client application commands. Let us understand the commands one by one in brief.
Create Command
Use the following Create command is used to create a digital twin −
CreateDigitalTwin dtmi:example:Floor;1 floor0 FloorName string First
After executing the command, you could see the follwing respnse on your console,
CreateDigitalTwin dtmi:example:Floor;1 floor0 FloorName string First Preparing.. Submitting.. Twin 'floor0 created successfully!
Update Command
If you want to update any changes for the digital twin, then use the following command. For example −
UpdateDigitalTwin floor0 add /FloorName string Second
After executing this command, you could see the following response on your console,
twin was updated successfully.
If you want to verify the changes, then run the following command −
GetDigitalTwin floor0
The above command will reflect the updated name on your console.
Twin Graph
We can create relationships between two twins using Twin graph. It is used to represent an entire environment. Lets create one more twin now,
CreateDigitalTwin dtmi:example:Room;1 room0 RoomName string FirstRoom
After executing the command, you could see the following response on your console −
CreateDigitalTwin dtmi:example:Room;1 room0 RoomName string FirstRoom Preparing.. Submitting.. Twin 'room0 created successfully!
Now, we have added one more twin. Let us combine both twin now using the following command −
CreateRelationship floor0 contains room0 relationship0
The above command add a "contains" relationship from floor twin corresponding to room twin.
After executing the command, you could see the following response on your console −
CreateRelationship floor0 contains room0 relationship Submitting.. Relationship relationship0 of type contains created successfully from floor0 to room0
We can verify the relationships with the below command,
GetRelationships floor0
The following block diagram depicts the relationship between the two twins −

Query Command
To list out all the environment questions in twin graph, we can execute the below command,
Query
The above command displays each digital twin with its details. To list out all the digital twins instances use the below command,
Select * from digitaltwins
Clean Up Resources
If you want to clean up resources in digital twins, run the following command −
az group delete --name <'your-resource-group>