Not sure where you got this script, but it looks like another AI "hallucination". There is no SignInActivity property for service principal objects, the only way to get such information is to crawl the sign-in logs, which in turn only keep data for 30 days. Alternatively, you can use the servicePrincipalSignInActivities report: https://learn.microsoft.com/en-us/graph/api/reportroot-list-serviceprincipalsigninactivities?view=graph-rest-beta&tabs=http
Here's a ready to use script that takes the second approach: https://www.michev.info/blog/post/5922/reporting-on-entra-id-integrated-applications-service-principals-and-their-permissions
And for application registrations, you can use: https://www.michev.info/blog/post/5940/reporting-on-entra-id-application-registrations