Overview
Background
When you migrate a Windows source server, you need to ensure that the source server can resolve the interface domain names of related cloud services. This usually involves editing the hosts file on the source server. If there are a large number of servers to be migrated, manual editing is time-consuming. To simplify this process, we provide example scripts for batch editing. You can use the scripts to quickly write the mappings between domain names and IP addresses to the hosts file on all source servers in batches.
Script Description
The scripts are developed using the PowerShell language and can run only on Windows. They are used to batch update and restore the /etc/hosts file on Windows source servers. The path of the hosts file is C:\Windows\System32\drivers\etc\hosts.
To prevent long script execution, a maximum of 100 servers can be modified at a time.
The following table describes for what and where the scripts are used.
Script |
Description |
Scenario |
---|---|---|
update_hosts_win.ps1 |
Batch update the hosts file on Windows source servers. The script will automatically log operations, alert for any exceptions, and generate a summary of the operations. |
Before migrating Windows source servers, run this script to update the hosts file for the servers. |
rollback_hosts_win.ps1 |
Batch restore the hosts file on Windows source servers. The script will automatically log operations, alert for any exceptions, and generate a summary of the operations. |
After the Windows source servers are migrated, run this script to restore the hosts file on these servers to the state before the migration. |
PowerShell Version and Dependency Requirements
PowerShell remoting uses WinRM, which provided by the Windows Management Framework (WMF).
- Windows PowerShell 3.0 or later (WMF 5.1 is recommended.)
- Microsoft .NET Framework 4.0 or later
- WinRM 3.0 or later
- Windows PowerShell 2.0 or later
- Microsoft .NET Framework 2.0 or later
- WinRM 2.0
Features that run only on Windows PowerShell 3.0 or higher, such as the ability to disconnect and reconnect to sessions, are only available when both computers are running Windows PowerShell 3.0 or higher.
$PSVersionTable
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot