How to restore/create linked server logins from one server to another
You can use Copy-DbaLinkedServer from dbatools to migrate linked servers.

For login migration, you can use copy-dbalogin

Just install dbatools and you will get all the cmdlets.

Also, see my answer if you want to dump the scripted output into file.