Add verification that source database is accessible
Add verification that source database is accessible

Adding this verification before removing the user in the destination database will ensure that the user is not removed, when the source database is in the offline/restoring state. It will also ensure that the script won't be accessing a non-accessible database.
Right now, if you are trying to copy a login using Copy-DBALogin function from a server where certain database is offline/restoring, this user will be completely removed from the same database on the destination server. The script will throw an error when trying to access the OFFLINE database.
Scenario, where it can be used: during a database migration that uses log backup chain, where last log backup has been taken WITH NORECOVERY. Databases will be restored on the target server, but will stay in a "Restoring" state on the source server. In current implementation, all the users will be stripped from the target databases when using Copy-DBALogin. Better option would be to keep them intact and afterwards fix them by using Repair-DBAOrphanUser (if needed).
Splaxi/dbatools,sqlpadawan/dbatools,kozloski/dbatools,SirCaptainMitch/dbatools,wsmelton/dbatools,dsolodow/dbatools