求助 Powershell 像 awk 一样输出字符


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

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

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

1 Answers
1
Best Answer
神经元短路 answered 5 年 ago

可以这样

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

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

Mooser Lee 管理员 replied 5 年 ago

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

Net replied 5 年 ago

好的谢谢解答