To generate a script to drop or map the orphan users in a SQL Server Instance
The dbatools module has already solved this for you.

Get-DbaDbOrphanUser - reports all users in one or more databases with no corresponding login
Repair-DbaDbOrphanUser - finds orphan users and if there is a login with the same name, it will remap them.
Remove-DbaDbOrphanUser - locates orphaned users and drops them from the database (you can do this with Repair-DbaDbOrphanUser -RemoveNotExisting as well).