Identifying Service principal-less authentication

Read this article first.

Rather than go via the portal, and because I wanted an excuse to refresh my very basic KQL chops, I came up with query:

This will show all the service principal less sign-ins, along with the resource they are trying to access and whether it is currently failing or not.

I suppose one could just pipe this to PowerShell to create the service principal as needed. Like thus:

Of course, don’t do that! 😊 The article doesn’t state it explicitly, but the idea is to verify that the app in question is genuine, and then create the sevice principal. So ideally one would generate a report that sends over the failed authentications (e.g. a Logic App that runs the query, puts it into an HTML table, and sends an email), and after a review and confirmation that this is genuine, the service principal is created (manually or via some automated process that kicks in after the review).