Sometime you may require to get a clone of your windows ec2 instance on AWS which was already registered with your domain. But this new cloned instance will not get added to the domain (Microsoft Active Directory / AWS Simple AD) it self. There are few tweaks that you need to follow up in order to get this done.
Prerequisites – In order to work with AWS Systems Manager you’ll need to create a role with iam permissions to access AWS SSM and attach it to your instance.
Login to you AWS account and go for AWS Systems Manager. From there select “Session Manager” and then click on “Start Session”
Now from the next window you’ll get to search your cloned instance. Here I’ve searched it with the instance ID and then click on “Start Session”.
Your session will get start in a new console, now you can run below command to remove the cloned server from domain.
netdom remove <current_hostname_of_instance> /Domain:<domain_name> /UserD:<admin_username> /PasswordD:"<admin_password>" /Force
As you can see in the output now you’ll need to restart the server.
Once server is restarted follow step 1 – step 2, then run the following command to update your hostname to a new one.
netdom renamecomputer <current_hostname_of_instance> /newname:<new_hostname_of_instance>
Finally now it’s time to register your cloned instance back to the domain as new instance. Run the following command and reboot the instance again.
netdom join <new_hostname_of_instance> /Domain:<domain_name> /UserD:<admin_username> /PasswordD:"<admin_password>"