Cmdlet Network and System Management
<
PowerShell can not only manage local files, processes, and services, but also has powerful networking and system-level operation capabilities. Whether viewing IP, testing network connectivity, or getting system information and managing user accounts, PowerShell provides rich and unified Cmdlets.
This section will help you master the most commonly used commands for network and system management, taking you from "command line user" to "system management expert."
I. Network management related Cmdlets
Test network connectivity:Test-Connection
Similar to ping command, but the output is an object, supporting more operations.
Test-Connection -ComputerName www.baidu.com -Count 4
Quick version (PowerShell 7+):
Test-NetConnection www.baidu.com
Get local IP configuration:Get-NetIPAddress
Get-NetIPAddress
View IPv4 addresses only:
Get-NetIPAddress -AddressFamily IPv4
Or via a legacy command compatibility method:
ipconfig
Or a more general WMI command:
Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled }
Get current network connection status:Get-NetTCPConnection
List all TCP connections and port status (similar to netstat):
Get-NetTCPConnection
View connection status of a specific port:
Get-NetTCPConnection -LocalPort 80
Manage hostname and DNS cache
Get the local hostname:
$env:COMPUTERNAME
Clear the DNS cache:
Clear-DnsClientCache
II. System Information Query
Get operating system information:Get-ComputerInfo
Get-ComputerInfo
Filter key fields (such as OS version, CPU):
Get-ComputerInfo | Select-Object OSName, WindowsVersion, CsProcessors
Get system uptime
(Get-CimInstance -Class Win32_OperatingSystem).LastBootUpTime
Get disk information:Get-Volume
Get-Volume
You can also use:
Get-PSDrive -PSProvider FileSystem
Or:
Get-CimInstance Win32_LogicalDisk | Select-Object DeviceID, VolumeName, Size, FreeSpace
Get BIOS and hardware information
Get-CimInstance -ClassName Win32_BIOS
Get-CimInstance -ClassName Win32_ComputerSystem
III. User and Account Management (Local)
Get current user information
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
or:
$env:USERNAME
View the local user list (Windows local accounts)
Get-LocalUser
Disable a user:
Disable-LocalUser -Name "TestUser"
Enable a user:
Enable-LocalUser -Name "TestUser"
Note: must be run as administrator.
Add a new user (local)
New-LocalUser -Name "NewUser" -Password (Read-Host -AsSecureString "输入密码")
IV. System Settings Operations
Set the system time zone
Set-TimeZone -Id "China Standard Time"
View supported time zones:
Get-TimeZone -ListAvailable
Set the system hostname (requires restart to take effect)
Rename-Computer -NewName "MyNewPC" -Restart
Set the system time (requires administrator privileges)
Set-Date -Date "2025-07-22 10:30"
V. Practical Scenario Examples
Example 1: Test connectivity from the local machine to multiple target hosts
"192.168.1.1", "8.8.8.8", "www.baidu.com" | ForEach-Object {
Test-Connection -ComputerName $_ -Count 2
}
Example 2: List currently open TCP ports (status Listening)
Get-NetTCPConnection | Where-Object { $_.State -eq "Listen" }
Example 3: Generate a system information report
$report = Get-ComputerInfo | Select-Object OSName, OSArchitecture, CsName, CsProcessors, WindowsVersion
$report | Out-File -FilePath "C:\SystemReport.txt"
VI. Summary
PowerShell provides powerful networking and system management capabilities, far beyond traditional command-line tools:
- Network operations support testing, monitoring, and configuring IP and ports
- System information commands make it easy to generate diagnostic reports and automated audits
- Local account management is suitable for small systems or workgroup environments
- All commands are object-oriented, flexibly combinable, and scriptable