PowerShell is a new feature specifically designed for system administrators in Windows Server 2008. PowerShell can be used to implement powerful functions under the command line. This article uses some examples to introduce how PowerShell implements common network commands. Finally, we use a combination of examples to introduce the two main features of PowerShell.
If our Windows Network Administrator is required to use the command line character interface during daily management operations, it is estimated that most Windows administrators will oppose this approach, because Windows command line tools have always had weak functions. With the release of Windows PowerShell, this situation will change. PowerShell allows administrators to do a lot of things they can't do on the command line interface.
This article describes how to use PowerShell command lines to execute some common network functions.
1. What is PowerShell?
PowerShell is a new feature of Windows Server 2008. To install PowerShell, You need to select and install the Powershell feature in the new feature wizard. The installation can be completed in about one minute. Then you can see the amazing command line scripting language. Unlike other scripting languages in Windows, PowerShell is designed specifically for system administrators. Powershell requires the. NET Framework and cmdlets command set. As a PowerShell user, you can use the cmdlets that comes with the system, or you can customize cmdlets to expand and implement more powerful functions.
Once PowerShell is installed, you can view Windows PowerShell 1.0 in the Start Menu> All programs. Click the Windows PowerShell option. Then, you can see a blue CLI window, as shown in:
Figure 1: Windows Powershell command line window
Before each prompt line, there is a sentence:
Always remind you that you are currently in the PowerShell command line.
Now let's take a look at how to use PowerShell to complete some common network commands.
2. List Server IP addresses
In Windows 2008, use the following command line to list server IP addresses:
You can see output results similar to the following:
Figure 2: using Windows PowerShell to list IP addresses
As shown in figure 2, the adapter of the Windows 2008 server has an IPV4 address and an IPV6 address. This feature is not surprising in itself. You can try to add other script features.
The output result of this command is an array. If you only want to see the IP address, you can modify the "select-Object" parameter to disable IPV6. The command line is as follows:
You can see the following output content:
Figure 3: Use Windows PowerShell to list only IPV4 addresses
3. Use PowerShell to list network adapter configurations
Run the following command to display the basic configuration information of the network adapter:
After the preceding command is executed, you can see the following output content:
Figure 4: Use PowerShell to display network adapter configuration information
4. Use PowerShell to implement the Pinging Function
Although you can still execute all common Windows commands such as ping on PowerShell command lines, PowerShell is more powerful and you can easily adjust the output items as needed.
In the following example, use Win32_PingStatus to output the result and select-Object to parse the result so that the final output result only displays the response time and status code of the output.
Shows the command line:
You can see the following output content:
Figure 5: Use select-Object in PowerShell to parse the Ping result
5. Windows Powershell shares a folder
The following PowerShell command shares the directory C: \ temp as "David temp ":
You can also directly use the net share command to implement the directory sharing function, as shown below:
6. Use PowerShell to implement complex network commands
If you just want to use PowerShell technology to achieve the most basic network management, you may feel very frustrated and will not use it. As with any other scripting language, PowerShell also has a learning curve. Once you pass this learning curve and learn how to use PowerShell, you will benefit from it. Using PowerShell will greatly save your time and improve efficiency.
Most PowerShell commands have a "computername" parameter. If we specify this parameter as "."), it indicates a local host. However, we can also specify this parameter as any IP address or computer name in the LAN. After the PowerShell script is created, it can run not only on the local computer, but also on all computers on the network.
For example, if you want to know the NIC configuration information of the computer named Dell9400 in the LAN, run the following command:
You can see the following output content:
Figure 6: Using Powershell to list Nic configurations of a remote computer
PowerShell has two main features:
The first feature is the ability to obtain remote computer information, as shown in figure 6.
Another major feature is the ability to filter the output and to use the output of one command as the input of another command. See the following command:
The preceding Command performs the following three steps:
1) Three IP addresses and domain names are listed first;
2) the three values in this list are used as the input parameters of "ForEach-Object". For each value, run the "Get-WmiObject" PingStatus command once separately, ping each IP address or domain name;
3) The Ping result is parsed using the select-Object method as the input parameter. Only the IP address, remote response time, and status code are displayed.
The output result is as follows:
Figure 7: PowerShell composite command example
In this example, we can see the power of PowerShell. You can combine the output of one command as the input of another command to achieve the purpose of system management.
7. Summary
Windows PowerShell is very powerful. This article only introduces some functions that Powershell can implement. It is hoped that these functions will inspire you to learn more about PowerShell.
It should be noted that, although PowerShell is a new feature in Windows Server 2008, PowerShell is not only running in Windows Server 2008. PowerShell can also be used in Windows XP, Vista, or Server 2003. You only need to download and install the PowerShell installer separately.