Look for a particular file via discovery

tomcollins
Tera Contributor

All,

I'm new to the ServiceNow platform and the world of custom probes/sensors and I have searched but cannot find what I'm looking for.

I am looking for a way during Windows discovery, to look for a particular file (defined name/path) and gather the Modified date of the file. I would like to populate 2 variables:

-         Is the file detected?

-         What is the modified date

This would allow me to detect if a particular app that's installed is configured (the log file is only created if its configured). I already know that the app is installed because it is part of the image and discovered via normal discovery. Searching the registry will not work because the attribute I would look at is already populated as part of the image

I'm thinking that someone has had to create some type of probe/sensor to discover if a file is present and either just report the file exists or parse the actual file. If so, I can build off of someone's already great work.

Thanks in advance!

4 REPLIES 4

doug_schulze
ServiceNow Employee
ServiceNow Employee

Thomas,



Easy as creating a Powershell probe with a probe parameter that has



launchProcess -computer $computer -cred $cred -command 'dir c:\text.txt'



I got a result:



Volume Serial Number is 3448-1EEA




Directory of c:\




04/29/2016   12:49 PM                                 0 text.txt


1 File(s)                           0 bytes


0 Dir(s)   191,740,444,672 bytes free



You can then parse out the date time value in your sensor using the 1 File(s) as your trigger to move ahead or bail if its not there..



May be better ways and looking forward to any other replies..


Thanks for the info! I will give it to one of our windows engineers to see if they can provide the syntax needed for the probe/sensor. As I said, I'm new to all this and I don't know PowerShell. I don't need to read the file, just know its there and get the time/date info. Ill look at the current powershell probes for inspiration.



Thanks!


Thomas,



That is the syntax for the probe parameter, you would just replace the c:\text with your file and location!



launchProcess -computer $computer -cred $cred -command 'dir c:\text.txt'



So Its not reading the file , its just telling you the directory information including the date that you are looking for..


great, thanks