PowerShell脚本可一键完成Windows Admin Center(WAC)的下载、安装、防火墙放行、证书绑定与服务启动;需Windows Server 2016+、.NET 4.7.2+、管理员权限及公网访问,端口默认443。
powershell 脚本可以一键启用并配置 windows 服务器的远程管理中心(即 windows admin center,wac),但需注意:wac 本身不是系统内置角色,而是一个轻量级、基于 web 的管理工具,需单独下载安装。所谓“一键配置”,实际指通过 powershell 自动完成 下载、安装、服务注册、防火墙放行、证书绑定与启动 全流程。
确认前提条件与环境准备
脚本运行前必须满足以下基础要求:
- Windows Server 2016 或更高版本(推荐 Server 2019/2022)
- 已启用 .NET Framework 4.7.2+ 和 Web-Server(IIS)角色(WAC 可选 IIS 模式,但默认使用内置 web 服务器)
- 具备管理员权限,且 PowerShell 执行策略允许本地脚本(Set-ExecutionPolicy RemoteSigned -Force)
- 服务器能访问公网(用于下载 WAC 安装包)或已提前缓存 MSI 文件
下载并静默安装 Windows Admin Center
使用 PowerShell 直接从微软官方源下载最新稳定版(如 2310 版)并静默安装:
$wacUrl = "https://github.com/microsoft/windows-admin-center/releases/download/v2310.0.0/WindowsAdminCenter2310.msi" $wacPath = "$env:TEMP\WindowsAdminCenter.msi" Invoke-WebRequest -Uri $wacUrl -OutFile $wacPath Start-Process msiexec.exe -ArgumentList "/i","`"$wacPath`"","/qn","/l*v","$env:TEMP\wac_install.log","SME_PORT=443","SSL_CERTIFICATE_OPTION=generate" -Wait
说明:
– SME_PORT=443 指定 HTTPS 端口(可改 6516 等非特权端口,避免需管理员启服务)
– SSL_CERTIFICATE_OPTION=generate 表示自动生成自签名证书(生产环境建议替换为有效证书)
配置防火墙与服务启动
安装完成后,自动开启对应端口并确保服务运行:
# 开放端口(按实际 SME_PORT 值调整) New-NetFirewallRule -DisplayName "Windows Admin Center HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow -Enabled True <h1>启动服务(服务名通常为 "ServerManagementGateway")</h1><p>Start-Service ServerManagementGateway Set-Service ServerManagementGateway -StartupType Automatic
若端口被占用,安装时会失败;可先用 netstat -ano | findstr :443 检查并释放端口。
(可选)绑定已有证书并验证访问
若已部署企业 PKI 或有 PFX 证书,可用以下命令替换默认证书:
$pfxPath = "C:\cert\wac.pfx"
$pfxPassword = ConvertTo-SecureString "YourPass" -AsPlainText -Force
Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\LocalMachine\My -Password $pfxPassword
# 获取证书指纹
$thumbprint = (Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -eq "CN=wac.contoso.local"})[0].Thumbprint
# 绑定到 WAC 服务(需重启服务)
& "$env:ProgramFiles\Windows Admin Center\SMEWebApp.exe" --cert-thumbprint $thumbprint --port 443
Restart-Service ServerManagementGateway
完成后,在浏览器中访问 https:// 即可进入 WAC 控制台(首次访问需信任自签名证书)。


















