The above method to get the App Instance ID only works if the app is installed, & you are able to get to its details page. I ran into an issue where the app was partially removed & when trying to reinstall I saw this message
"You can't add this app here."
I couldn't go to the App Details page, as described in Vadim's answer, to get the App Instance ID.
So, I got the App Instance Id from this page instead
- Goto above link & Save the XML
- Open the xml in IE(or other xml reader) and search for your App's title
- Under the
<entry> tag, look for a GUID in the
<d:AppId> tag. This is the App Instance ID you are looking for.
Run Vadim's script above, with the app instance id, to remove the app in the limbo state. After I did this, the "You can't add this app here." message was cleared & I could reinstall the app.
Hope this helps someone out. I wanted to post this as a comment to Vadim's answer, but stackexchange rules won't allow me.