How to find if a file exists (in the local user's profile)
I can easily set up a custom inventory rule to identify systems that have a certain file if the file is in a static location, such as outlined here:
https://www.itninja.com/question/how-do-i-find-a-file-on-all-computers
However I'm tasked with finding computers that have a file in %userprofile%\appdata\Roaming\Microsoft\Word\STARTUP.
I'm having troubles getting this to work because from what I understand, the inventory is run as a service and therefore has no understanding of the dynamic userprofile folders. Any ideas?
0 Comments
[ + ] Show comments
Answers (1)
Answer Summary:
Please log in to answer
Posted by:
chucksteel
6 years ago
Top Answer
Here's a one liner that should work in a ShellCommandTextReturn
echo off & for /d %u in (\Users\*) do (if exist %u\appdata\Roaming\Microsoft\Word\Startup\filename.ext echo %u)
The echo off makes the display a little nicer and the output should be something like this:
\Users\user1
\Users\user1
\Users\user5
The users that have the file in their profile will be listed. This will also work for directories.
Comments:
-
You, sir, are a life saver. This is working fantastically. Thank you for taking the time. Am I correct in assuming that the "for /d %u in (\Users\*) do" section is the equivalent of "for each"? - ljg_gencode 6 years ago
-
Yes, it is the Windows command line version of a for each statement. - chucksteel 6 years ago