I have been testing out the recently released Managed Service Identity (MSI) for Azure and have successfully created an MSI for our App Services using the ARM template approach described in the documentation here: How to use Azure Managed Service Identity (public preview) in App Service and Azure Functions
However, I would like to grant access for the managed identity on other resources, such as a key vault. I have been able to do this through the portal, but need to be able to script it in PowerShell in order to integrate with our continuous deployment builds.
I have successfully created the access using PowerShell by executing Set-AzureRmKeyVaultAccessPolicy cmdlet. However I have only been able to do this with a hard-coded object id, manually copied and pasted from the portal once the MSI has been created.
My question is, how in PowerShell can I get a reference to the MSI's object id, so that I can grant access to it on other resources? The only examples I can find (such as this one), refer only to VMs and not App Services.