求助 Powershell 像 awk 一样输出字符


PowerShell交流中心 › 分类: 变量-函数-脚本-条件-循环-参数 › 求助 Powershell 像 awk 一样输出字符
0 赞 踩
Net asked 8 年 ago

Get-WmiObject -Class “Win32_NTDomain” | ForEach-Object {$_.DnsForestName}

WEM.local
想要获取 “.” (点后面的)所有字符串

1 Answers
1 赞 踩
Best Answer
神经元短路 answered 8 年 ago

可以这样

Get-WmiObject -Class “Win32_NTDomain” | ForEach-Object {($_.DnsForestName -split "[.]")[-1]}
Net replied 8 年 ago

你好,能解释下这个正规则表达式吗

Mooser Lee 管理员 replied 8 年 ago

这不是正则表达式,是根据圆点,分割字符串,【-1】,是取分割后的最后一个元素。

Net replied 8 年 ago

好的谢谢解答