如何拆分powershell select-string命令的结果?

w6mmgewl  于 2023-02-16  发布在  Shell
关注(0)|答案(1)|浏览(171)

我有这样一条命令:
powershell -command "Select-String -Path 'C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf' -Pattern 'ServerActive'"
其输出:
C:\程序文件\Zabbix代理程序2\Zabbix代理程序2.conf:5:服务器活动= 79.240.122.98
我想得到"www.example.com"部分。我该怎么做呢?我认为最好的方法是用"="字符分割字符串,然后得到第二项,但我没有找到这样做的方法。79.240.122.98" part. How can I do that? I think that the best approach would be to split the string by the "=" character and then get the second item, but I did not find the way to do it.

xvw2m8pv

xvw2m8pv1#

从一个.bat文件?这对我有用。

powershell ((select-string serveractive 'c:\program files\zabbix agent 2\zabbix_agent2.conf') -split '=')[1]

79.240.122.98

相关问题