Windows Server Migration Tools (WSMT) 允許將角色、功能、使用者、群組、設定從舊伺服器遷移至新伺服器。遷移完成後,工具本身佔用磁碟空間、擴大攻擊面、可能與新版本衝突。本文提供完整安裝版 (GUI)與Server Core (無 GUI)雙模式移除步驟,均以 PowerShell 為主,適合自動化腳本。注意:WSMT 移除不會影響已遷移的資料/設定。
# 1. 匯入 ServerManager 模組 (預設已載入,若無則執行)
Import-Module ServerManager
# 2. 確認目前安裝狀態
Get-WindowsFeature Migration
# 3. 移除遷移工具功能
Remove-WindowsFeature Migration -Restart:$false
# 4. 驗證移除結果
Get-WindowsFeature Migration | Format-Table Name, InstallState
# InstallState 應顯示 "Available" (未安裝)
Server Core 無 GUI,僅命令列。提供三種指令任選一,效果相同:
# 1. 進入 PowerShell
powershell
# 2. 匯入模組
Import-Module ServerManager
# 3. 移除
Remove-WindowsFeature Migration -Restart:$false
ocsetup 傳統指令 (相容舊腳本)ocsetup ServerMigration /uninstall
pkgmgr 封裝管理器指令 (最底層)pkgmgr /uu:ServerMigration
# PowerShell
Get-WindowsFeature Migration
# CMD
dism /online /get-features /format:table | findstr Migration
# State: Disabled / Removed 即成功
| 問題 | 原因 | 解決 |
|---|---|---|
| Remove-WindowsFeature 卡住/報錯 | 有其他功能相依 Migration (極少見) | 檢查 Get-WindowsFeature | Where DependsOn -like "*Migration*",先移除相依功能 |
| Server Core 下 ocsetup 無回應 | ocsetup 為非同步,需輪詢狀態 | 用 dism /online /get-features 輪詢或直接用 Remove-WindowsFeature |
| 移除後磁碟空間未釋放明顯 | WSMT 本身較小 (~50MB),主要空間在遷移暫存資料 | 清理 C:\Windows\Migration\、%TEMP%\Migration* 目錄 |
| 誤以為移除工具會刪除已遷移資料 | 工具與資料無關 | 放心移除,遷移完成的角色/設定/資料不受影響 |
Configuration RemoveMigrationTools {
Node $AllNodes.Where({$_.Role -eq "Server"}).NodeName {
WindowsFeature MigrationTools {
Name = "Migration"
Ensure = "Absent"
}
}
}
- name: Remove Windows Server Migration Tools
win_feature:
name: Migration
state: absent
when: ansible_os_family == 'Windows'
遷移工具屬於「一次性基建工具」,用完即走。掌握 Remove-WindowsFeature Migration (GUI/Core 通用)、ocsetup ServerMigration /uninstall、pkgmgr /uu:ServerMigration 三條等效路徑,將移除動作納入遷移專案收尾 Checklist、黃金映像建置腳本、合規性基線掃描,確保生產環境無殘留攻擊面、無多餘元件。乾淨的伺服器,才是安全的伺服器。