Updated on 2024-10-21 GMT+08:00

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).

To run remote sessions on PowerShell, the local and remote computers must have the following:
  • Windows PowerShell 3.0 or later (WMF 5.1 is recommended.)
  • Microsoft .NET Framework 4.0 or later
  • WinRM 3.0 or later
To run remote sessions on Windows PowerShell 2.0, the local and remote computers must have the following:
  • 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.

Run the following command to check the PowerShell version:
$PSVersionTable