เราต่างทราบกันดีว่าตั้งแต่ Windows 7 เป็นต้นมาก็มีการติดตั้ง Powershell มาให้โดย default ซึ่ง Powershell มีประสิทธิภาพในการใช้งานต่างๆไม่ต่างกับการใช้งาน terminal ใน Linux เลยทีเดียว ทีนี้มาดูกันว่าการใช้งาน Powershell ในเชิง Network เราสามารถใช้คำสั่งอะไรได้บ้างครับ
1. ดู Network information (คล้ายๆ ipconfig)
PS> Get-NetIPConfiguration
2. List network adapter
PS> Get-NetAdapter
3. List network adapter เฉพาะ Ethernet
PS> Get–NetAdapter –Name *Ethernet*
4. ดึงค่าของ Network Adapter เพิ่มเติม
PS> Get–NetAdapter | ft Name, Status, Linkspeed, VlanID
5. ดูค่า Driver ของ Network Adapter
PS> Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName
6. ดูข้อมูล Hardware ของ Network Adapter
PS> Get–NetAdapterHardwareInfo
7. Disable และ Enable Network Adapter
PS> Disable–NetAdapter –Name “Wireless Network Connection”
PS> Enable–NetAdapter –Name “Wireless Network Connection”
8. เปลี่ยนชื่อ Network Adapter
PS> Rename–NetAdapter –Name “Wireless Network Connection” –NewName “Wireless”
9. ดึงข้อมูล IP และ DNS
PS> Get–NetAdapter –Name “Ethernet” | Get–NetIPAddress
10. ดึงข้อมูลเฉพาะ IPv4
PS> (Get–NetAdapter –Name “Ethernet” | Get–NetIPAddress).IPv4Address
11. ดึงข้อมูลเฉพาะ DNS
PS> Get–NetAdapter –Name “Ethernet” | Get–DnsClientServerAddress
12. Set IP ให้กับ Network Interface
PS> New–NetIPAddress –InterfaceAlias “Ethernet” –IPv4Address 10.0.1.95 –PrefixLength “24” –DefaultGateway 10.0.1.1
13. ลบ IP Address
PS> Get–NetAdapter –Name “Ethernet” | Remove–NetIPAddress
14. Set DNS Server
PS> Set-DnsClientServerAddress -InterfaceAlias “Ethernet” -ServerAddresses “10.10.20.1”,”10.10.20.2″
15. กำหนดให้ network interface ใช้ DHCP
PS> Set–NetIPInterface –InterfaceAlias “Wireless” –Dhcp Enabled
16. Ping โดยใช้ computer name
PS> Test-NetConnection -ComputerName www.thomasmaurer.ch
17. Ping โดยใช้ computer name และบอกรายละเอียดเพิ่มเติม
PS> Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed
18. Ping แบบ Multi IP
PS> 1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize
19. Trace Route
PS> Test-NetConnection -ComputerName www.thomasmaurer.ch –TraceRoute
20. Scan Port
PS> Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80
PS> Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP
21. NSLookup
PS> Resolve–DnsName www.thomasmaurer.ch
PS> Resolve–DnsName www.thomasmaurer.ch –Type MX –Server 8.8.8.8
22. Routing โดยใช้ Powershell
PS> Get–NetRoute
PS> Get–NetRoute –Protocol Local –DestinationPrefix 192.168*
PS> Get–NetRoute –InterfaceAlias Ethernet
PS> New–NetRoute –DestinationPrefix “10.0.0.0/24” –InterfaceAlias “Ethernet” –NextHop 192.168.192.1
23. Netstat
PS> Get–NetTCPConnection
PS> Get–NetTCPConnection –State Established
24. Create NIC Teaming
PS> New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic
25. SMB Client Configuration
PS> Get–SmbClientConfiguration
26. SMB Connection
PS> Get–SmbConnection
27. SMB Mutlichannel Connections
PS> Get–SmbMultichannelConnection
28. SMB Open files
29. SMB Direct (RDMA) adapters
PS> Get–NetAdapterRdma
สำหรับข้อที่เหลือนี้สำหรับเครื่องที่ใช้ Hyper-V ครับ
30. Network Adapter VMQ Settings
PS> Get-NetAdapterVmq
# Disable VMQ
PS> Set-NetAdapterVmq -Enabled $false
# Enable VMQ
PS> Set-NetAdapterVmq -Enabled $true
31. VM Network Adapter detail
PS> Get–VMNetworkAdapter –VMName Server01
32. VM Network Adapter IP Address
PS> (Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses
33. VM Network Adapter Mac Address
PS> (Get–VMNetworkAdapter –VMName NanoConHost01).MacAddress