手上有主機要移轉了,舊主機是 Windows 2003、新主機是 Windows 2008,頭痛的是,以前備分排程檔,都是直接把副檔名為 *.job 的排程檔直接複製貼上到 C:\Windows\Tasks,但在 Windows 2008 就不能這樣玩了。

佛心來的同事幫我找了幾個連結:

  1. "Importing scheduled tasks from Windows Server 2003 to Windows Server 2008"
    將 Windows 2003 的 JOB 檔複製到 Windows 2008,然後再做一點處理
  2. "Powershell, and exporting Windows Scheduled Tasks"
    用到 PowerShell 來處理
  3. "Transfer scheduled tasks to Server 2008"
    進入 Windows 2008 主機的「工作排程器」(taskschd),在左側樹狀選單的「工作排程器 (本機)」→右鍵選單「連線到另一台電腦」設定連接到 Windows 2003 主機

後來我採用的是第一種方法,因為我自己在這個討論串也有看到相同解法:"Is there a way to import a scheduled task from windows 2003 (.job) to windows 2008 (.xml)?"

根據經驗法則,比較常出現的方法比較好操作,所以才會廣為流傳。我找到的這個討論串其實同時出現了方法一與方法三,但此時又發生一件殘念的事,就是我的 Windows 2008 主機沒辦法透過網路連線到 Windows 2003,只好動手想辦法把檔案複製到 Windows 2008、使用方法一來實作。



實際上的操作流程如下:

  1. 在 Windows 2003,將下列檔案收集到 "ScheduledTaskImport" 資料夾。
    • C:\WINDOWS\System32 資料夾裡的兩個檔案
      • schtasks.exe
      • schedsvc.dll
    • C:\WINDOWS\Tasks 資料夾裡的所有排程檔 (*.job)
  2. 在 ScheduledTaskImport 資料夾中,建立一個名為 "stask_convert.bat" 的批次檔,內容如下:
    :: stask_convert.bat
    @ECHO off
    echo --------------------------------------------------
    echo Running conversion of 2003 schedule tasks to 2008. Please wait...
    echo --------------------------------------------------

    for /f "delims=" %%i in ('dir /b /a-d-h-s *.job') DO (
    schtasks /change /TN "%%~ni" /RU administrator /RP YourPassword
    )
  3. 將 ScheduledTaskImport 資料夾整個複製到 Windows 2008 主機。
  4. 將 JOB 檔複製一份到 Windows 2008 的 C:\Windows\Tasks。
  5. 開啟命令提示字元,切換到 ScheduledTaskImport 資料夾,執行 stask_convert.bat。
    (如果你沒有將 JOB 檔複製到 C:\Windows\Tasks,會出現「錯誤: 系統中沒有指定的工作名稱 "XXX"。」的錯誤訊息)


匯入成功後,就可以在 Windows 2008 的工作排程器看到排程囉。



--
一些搜尋排程相關問題時找到但還沒實際用過的文章:

  1. 透過 PowerShell 把排程匯出成 Excel 文件檔:"Weekend Scripter: Use PowerShell to Document Scheduled Tasks"
  2. 透過 PowerShell 把 Windows 2003 的排程匯出到 Windows 2008:"Script to migrate scheduled tasks from Windows XP/Server 2003 to 7/Server 2008"
  3. 目前匯出的全部排程無法一次匯回去,錯誤訊息是 「工作的格式不正確,已回報下列錯誤:(2,3): Tasks:」 (“The format of the task is not valid. The following error was reported (2,3):Tasks:”)”Windows 7: Task Scheduler Import Error: 2,3” 這篇寫說在檔頭加上 FF FE (2 bytes) 就可以了,但我加了也沒用。但看“Powershell, and Exporting Windows Scheduled Tasks” 這篇說把排程通通匯出成一個 XML 後可以用 PowerShell 匯回去。
arrow
arrow
    全站熱搜

    小攻城師 發表在 痞客邦 留言(2) 人氣()