【发布时间】:2015-02-03 01:34:58
【问题描述】:
当你使用
(GWMI -ComputerName $server -Class Win32_OperatingSystem -ErrorAction Stop).Caption
得到类似的标题
Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
Microsoft Windows Server 2008 R2 Standard
Microsoft Windows Server 2012 Datacenter
从结果中删除"Microsoft Windows" 和"Microsoft(R) Windows" 的简单方法是什么?
我想出了:
(GWMI Win32_OperatingSystem -Comp $server).Caption -Replace "^Microsoft Windows "
这会将"Microsoft Windows Server 2012 Datacenter" 变成"Server 2012 Datacenter",但是 2003 和 2008 年的旧机器不匹配替换正则表达式。
【问题讨论】:
标签: regex powershell scripting