網路殼層 (Netsh) 範例批次檔案Network Shell (Netsh) Example Batch File

適用於:Windows Server 2016Applies To: Windows Server 2016

您可以使用本主題以了解如何建立 Windows Server 2016 中使用 Netsh 執行多工作批次檔。You can use this topic to learn how to create a batch file that performs multiple tasks by using Netsh in Windows Server 2016. 在此範例批次檔案中,netsh wins使用操作。In this example batch file, the netsh wins context is used.

範例「批次檔案概觀Example Batch File Overview

您可以使用 Netsh 命令 Windows 網際網路名稱服務 (WINS) 在「批次檔案及其他指令碼自動化工作。You can use Netsh commands for Windows Internet Name Service (WINS) in batch files and other scripts to automate tasks. 批次檔案下例示範如何使用 Netsh 命令 WINS 來執行各種不同的相關的工作。The following batch file example demonstrates how to use Netsh commands for WINS to perform a variety of related tasks.

在「批次檔此範例,WINS-A WINS 伺服器的 IP 位址 192.168.125.30,WINS-B 且 WINS 伺服器的 IP 位址 192.168.0.189。In this example batch file, WINS-A is a WINS server with the IP address 192.168.125.30 and WINS-B is a WINS server with the IP address 192.168.0.189.

範例「批次檔案達成下列工作。The example batch file accomplishes the following tasks.

  • 新增名稱動態筆 192.168.0.205 的 IP 位址、MY_RECORD [04h],以 WINS-AAdds a dynamic name record with IP address 192.168.0.205, MY_RECORD [04h], to WINS-A
  • 設定為 WINS-A 的推播日拉複寫協力廠商的 WINS-BSets WINS-B as a push/pull replication partner of WINS-A
  • 連接至 WINS-B,並將設定為推播日拉複寫協力廠商的 WINS-B WINS-A。Connects to WINS-B, and then sets WINS-A as a push/pull replication partner of WINS-B
  • 起始 WINS-B 推播複寫 WINS-A 從Initiates a push replication from WINS-A to WINS-B
  • 若要確認已成功複寫新記錄 MY_RECORD,WINS-B 連接Connects to WINS-B to verify that the new record, MY_RECORD, was replicated successfully

Netsh 範例批次檔案Netsh example batch file

以下的範例批次檔案,包含意見行的前面加上「rem,」的。In the following example batch file, lines that contain comments are preceded by "rem," for remark. Netsh 忽略意見。Netsh ignores comments.

rem: Begin example batch file.

rem two WINS servers:

rem (WINS-A) 192.168.125.30

rem (WINS-B) 192.168.0.189

rem 1. Connect to (WINS-A), and add the dynamic name MY\_RECORD \[04h\] to the (WINS-A) database.

netsh wins server 192.168.125.30 add name Name=MY\_RECORD EndChar=04 IP={192.168.0.205}

rem 2. Connect to (WINS-A), and set (WINS-B) as a push/pull replication partner of (WINS-A).

netsh wins server 192.168.125.30 add partner Server=192.168.0.189 Type=2

rem 3. Connect to (WINS-B), and set (WINS-A) as a push/pull replication partner of (WINS-B).

netsh wins server 192.168.0.189 add partner Server=192.168.125.30 Type=2

rem 4. Connect back to (WINS-A), and initiate a push replication to (WINS-B).

netsh wins server 192.168.125.30 init push Server=192.168.0.189 PropReq=0

rem 5. Connect to (WINS-B), and check that the record MY\_RECORD \[04h\] was replicated successfully.

netsh wins server 192.168.0.189 show name Name=MY\_RECORD EndChar=04

rem 6. End example batch file.

範例「批次檔案中使用 WINS Netsh 命令Netsh WINS commands used in the example batch file

下列區段清單netsh wins在此範例程序中所使用的命令。The following section lists the netsh wins commands that are used in this example procedure.

  • 伺服器server. 將目前的 WINS command\ 列操作切換到依其名稱或 IP 位址所指定的伺服器。Shifts the current WINS command-line context to the server specified by either its name or IP address.
  • 新增名稱add name. 暫存器 WINS 伺服器上的名稱。Registers a name on the WINS server.
  • 新增協力廠商add partner. 新增複寫合作夥伴 WINS 伺服器上。Adds a replication partner on the WINS server.
  • 初始化推播init push. 初始並 WINS 伺服器來傳送推播觸發程序。Initiates and sends a push trigger to a WINS server.
  • 顯示名稱show name. 顯示的特定 WINS 伺服器資料庫中的詳細的資訊。Displays detailed information for a particular record in the WINS server database.

如需詳細資訊,請查看網路 Shell (Netsh)For more information, see Network Shell (Netsh).