Hi,
I need create a powershell script to find 'good day' in a file, and if string was found,
print 'statistic: 1' (APM's input data).
Thanks a lot.
Hello contracer,
You can use "select-string" PowerShell command. The simple PowerShell script for searching string in a file could look like:
$FileName = "C:\FileName.txt" $SearchString = "good day" $Sel = select-string -pattern $SearchString -path $FileName If ($Sel -eq $null) { echo "Statistic: 0" } Else { echo "Statistic: 1" }
Or you can import one of the APM templates from thwack for file text monitoring (but these templates are vbscripts):
Kind Regards,
Lukas Belza (SolarWinds development)
This script works to find a string in a file in a remote server ?
Hello,
You can change the "Execution Mode" to "Remote Host" when editing Windows PowerShell Monitor. Remote Host can execute scripts remotely (on the selected target node) using the Windows Remote Management (WRM) system component.
You need to configure WRM on both (Orion and target machine).
On Orion machine you can use following command to add the target machine as trusted host:
winrm set winrm/config/client @{TrustedHosts ="10.199.1.2"}
On the target machine use following command:
winrm quickconfig
Press "y" when you see Make these changes [y/n]? question. This command configures the WinRM automatically.
Then you should monitor the file on the remote machine.
Sorry to add to an old post- while I am able to get this to work after doing the above steps (winrm quickconfig, set client) I would prefer to run this as a powershell script only on the local orion poller and allow it connect with UNC path to the remote system. For example rather then using this which works with remote execution;
$sel = select-string -path C:\test_file.txt -pattern "text"
If ($sel -eq $null)….
I would prefer to use this with local execution;
$sel = select-string -path \\${IP}\c$\test_file.txt -pattern "text"
If I enter the above into a PS window on the main or additional pollers they work great - but return no path found when executed through the powershell monitor component. I it possibly not passing through the credentials and should I try to pass credentials in the script?
Most of our systems are locked down and no way I'll get permission to setup listeners on all the clients when UNC path will work.