/build/static/layout/Breadcrumb_cap_w.png

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:
Posted by: chucksteel 5 years ago
Red Belt
4

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\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 5 years ago
    • Yes, it is the Windows command line version of a for each statement. - chucksteel 5 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ