在 Windows Server 2022 Core(无桌面版) 中,由于没有图形界面(GUI),所有管理操作必须通过命令行工具完成。你可以使用以下几种方式来高效地管理和配置系统:
🔧 一、常用命令行与 PowerShell 工具
1. 命令提示符(Command Prompt)
虽然功能有限,但可执行基础命令。
ipconfig # 查看网络配置
netstat -an # 查看端口监听状态
ping server01 # 测试网络连通性
sfc /scannow # 系统文件检查
⚠️ 推荐优先使用 PowerShell,更强大且支持远程管理。
2. PowerShell(推荐)
PowerShell 是 Windows Server Core 的主要管理工具,支持模块化和脚本化操作。
📌 常用管理任务示例:
✅ 查看系统信息
Get-ComputerInfo | Select-Object CsName, OsName, OsArchitecture, WindowsVersion
✅ 网络配置
# 查看网卡
Get-NetAdapter
# 设置静态 IP
New-NetIPAddress -InterfaceIndex 3 -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1
# 设置 DNS
Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses 8.8.8.8, 8.8.4.4
# 查看 IP 配置
ipconfig /all
✅ 主机名设置
Rename-Computer -NewName "SRV-WEB01"
Restart-Computer # 重启生效
✅ 加入域
Add-Computer -DomainName "contoso.com" -Credential contosoadministrator
Restart-Computer
✅ 启用远程管理(WinRM)
Enable-PSRemoting -Force
Set-Item wsman:localhostClientTrustedHosts -Value "*" -Force
注意:生产环境建议指定具体 IP 或域,避免使用
*。
✅ 安装角色和功能(如 IIS、DHCP、AD 等)
# 安装 Web 服务器(IIS)
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# 安装 Active Directory 域服务
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
# 安装 DHCP 服务器
Install-WindowsFeature -Name DHCP -IncludeManagementTools
-IncludeManagementTools会安装对应的 PowerShell 模块。
✅ 查看已安装功能
Get-WindowsFeature | Where-Object Installed -eq $true
✅ 用户和本地组管理
# 创建用户
New-LocalUser "john" -Password (ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force)
# 添加到管理员组
Add-LocalGroupMember -Group "Administrators" -Member "john"
# 查看用户
Get-LocalUser
Get-LocalGroupMember -Group "Administrators"
✅ 时间同步
# 设置时间服务器
w32tm /config /syncfromflags:manual /manualpeerlist:"time.windows.com"
w32tm /config /update
w32tm /resync
✅ 防火墙配置
# 允许 ICMP(ping)
Set-NetFirewallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)" -Enabled True
# 允许特定端口(如 80)
New-NetFirewallRule -DisplayName "HTTP In" -Protocol TCP -LocalPort 80 -Action Allow -Direction Inbound
🖥 二、远程管理方式(推荐)
由于 Server Core 无 GUI,通常通过远程连接进行管理。
1. 使用 PowerShell 远程(PowerShell Remoting)
确保目标服务器启用了 WinRM。
# 从管理机连接
Enter-PSSession -ComputerName 192.168.1.100 -Credential Administrator
# 执行命令后退出
Exit-PSSession
2. 使用 RSAT 工具(远程服务器管理工具)
在 Windows 10/11 或带桌面的 Windows Server 上安装 RSAT,然后远程管理 Core 服务器。
-
安装 RSAT:
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 # RSAT 功能可通过“可选功能”添加,或使用 DISM -
使用 MMC 控制台(如 ADUC、DHCP 管理器)连接远程 Core 服务器。
3. 使用 Windows Admin Center(WAC)
微软推荐的轻量级图形化管理工具。
步骤:
- 在另一台机器上部署 Windows Admin Center
- 将 Server Core 添加为受管节点
- 通过浏览器图形化管理(事件日志、性能、存储、更新等)
✔ 支持 HTTPS、证书认证、集中管理多台服务器。
🛠 三、其他实用技巧
1. 启用 SSH 服务(方便 Linux 用户)
# 安装 OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# 启动并设置开机启动
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
# 允许防火墙
New-NetFirewallRule -DisplayName "SSH Server" -Protocol TCP -LocalPort 22 -Action Allow -Direction Inbound
之后可用 PuTTY、VS Code Remote SSH 等连接。
2. 更新系统
# 检查更新
Install-Module -Name PSWindowsUpdate -Force
Import-Module PSWindowsUpdate
Get-WindowsUpdate
# 安装更新
Install-WindowsUpdate -AcceptAll -AutoReboot
或使用原生命令:
# 仅检查(需配合第三方脚本) # 原生不提供直接安装更新的 cmdlet,推荐使用 WUA API 或组策略/WSUS。
3. 日志查看
# 查看系统事件日志(错误)
Get-EventLog -LogName System -EntryType Error -Newest 10
# 查看应用程序日志
Get-WinEvent -LogName Application -MaxEvents 10 | Where-Object Level -eq 2
✅ 总结:最佳实践建议
| 任务 | 推荐工具 |
|---|---|
| 日常配置 | PowerShell |
| 远程管理 | PowerShell Remoting 或 Windows Admin Center |
| 图形化操作 | Windows Admin Center(部署在外部) |
| 批量自动化 | PowerShell 脚本 .ps1 |
| 安全连接 | SSH 或 WinRM over HTTPS |
📚 学习资源
- Microsoft Learn: Manage Windows Server Core
- PowerShell Docs
- Windows Admin Center 文档
如有具体场景(如搭建域控、Web 服务器、故障排查),欢迎继续提问!
云小栈