echo This will synchronize DCs
Note
If you want to include the pipe (|), the
less-than character (<), the greater-than character (>), or the
caret (^) symbol in an echo line, you need to precede the character with
a caret (^). For example, if you want to send the output of the command
to a text file with the > symbol, you would have to list it as
^>.
3. Using Parameters
Windows Server 2008 supports the use of parameters in
batch files. You define the parameter in the batch file, and then you
can pass data to the batch file as a parameter. You can use as many as
nine parameters, and they are defined as %1 through %9.
As an example, consider the whoami command. You can enter the following command to view the SID of the currently logged-on user:
You see information similar to the following:
USER INFORMATION
----------------
User Name SID
============== ==============================================
pearson\darril S-1-5-21-4285671909-4150961583-1987988917-1000
You can create a one-line batch file named who.bat with the following line:
who.bat Batch File Contents | Result When Executed at Command Prompt | Comments |
---|
whoami /%1 | c:/>who user
USER INFORMATION
----------------
User Name SID
=====================================
pearson\darril S-1-5-21-4285671909-
4150961583-987988917-1000
| This command (whoami /%1) actually runs the following command by substituting user for %1:whoami /user |
Although the previous example is simplistic, it does
show how a parameter is used. The following example shows a more usable
batch file that can be used to set the IP address, subnet mask, and
default gateway of a Windows Server 2008 Server Core system from the
command line. Note that even though it runs to two lines in the text, it
is entered on a single line.
netsh interface ipv4 set address name = "local area connection"
static 10.10.0.10 255.0.0.0 10.10.0.1
The previous command sets the IP address to 10.10.0.10, the subnet mask to 255.0.0.0, and the default gateway to 10.10.0.1.
You can create a batch file named setip.bat with the
following line using parameters. The batch file accepts three parameters
identified as %1, %2, and %3:
netsh interface ipv4 set address name = "local area connection"
static %1 %2 %3
setip.bat Batch File Parameters | Executing setip.bat at Command Prompt | Comments |
---|
| c:/>setip 10.10.0.10
255.0.0.0 10.10.0.1
| This command sets the IP address, subnet mask, and default gateway using the setip.bat file. |
You can add a second line to your batch file to also
set the address of the DNS server. Notice that the %4 parameter is the
actual IP address of the DNS server.
netsh interface ipv4 set address name="Local Area Connection"
static %1 %2 %3
netsh interface ipv4 set dnsserver "Local Area Connection" static %4
setip.bat Batch File Parameters | Executing setip.bat at Command Prompt | Comments |
---|
%1 %2 %3 %4 | c:/>setip 10.10.0.10
255.0.0.0 10.10.0.1
10.10.0.5
| This command sets the IP address, subnet mask, default gateway, and DNS server address using the setip.bat file. |