Home > Mobile >  How can I split the result of powershell select-string command?
How can I split the result of powershell select-string command?

Time:01-27

I have a command like this:

powershell -command "Select-String -Path 'C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf' -Pattern 'ServerActive'"

Which outputs:

C:\Program Files\Zabbix Agent 2\zabbix_agent2.conf:5:ServerActive=79.240.122.98

I want to get the "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.

CodePudding user response:

From a .bat file? This works for me.

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

79.240.122.98
  • Related