Scripting Question

How to find if a file exists (in the local user's profile)

08/16/2018 1455 views
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:

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?
Answer Summary:
0 Comments   [ + ] Show comments


Answer Chosen by the Author

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:

The users that have the file in their profile will be listed. This will also work for directories.

Answered 08/17/2018 by: chucksteel
Red Belt

  • 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"?
    • Yes, it is the Windows command line version of a for each statement.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


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