You can find the ObjectId for your managed identity in the Azure Portal.
- Go to your automation account
- Click "Identity" from the menu list to the left
- Copy the ObjectID
In the code, set the '$ManagedIdentityId' variable to the ObjectID for your managed identity.
You must be Global Admin to give permissions.