Batch file to use psgetsid.exe to check mulitple sids in a text file

I had this question after viewing SID account to username.

I tried creating the batch file to run through a text file with SIDs in it. This is what i came up with

@echo off
>output.txt (
for /f %%i IN (unresolvedsids.txt) DO C:Desktop\psgetsid.exe %%i
)

When i run it, it creates an empty output file, this is my first attempt at a batch file so i'm not very sure how to troubleshoot what is happening behind the scenes when you click the .bat file
Lauren QuattrocchiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex GreenProject Systems EngineerCommented:
If the unresolved SIDS aren't found, it won't give you an output in the first place. Do the accounts or groups even exist is more the question.
Lauren QuattrocchiAuthor Commented:
I'm running this to check if they exist so I don't know if they exist. When I run the command individually in cmd I get the message no mapping between account names and security IDs was done, I was expecting the output file to contain this message, I also have a sid in the text file that I know resolves, and it outputs the group when i run it individually but the output is still empty from the .bat file. Thanks
NVITEnd-user supportCommented:
This is tested and works...

@echo off
 
for /f %%i IN (unresolvedsids.txt) DO C:\Desktop\psgetsid.exe %%i >>output.txt

Open in new window


Also, just checking but... is that where psgetsid.exe is located, i.e. C:\Desktop?
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Lauren QuattrocchiAuthor Commented:
I tested and that way an output file is not create,d and yes it is located on the desktop specifically C:\users\[username]\desktop, which i have in my file path i just took it out  when i posted here for simplicity sake
NVITEnd-user supportCommented:
> ...an output file is not create,d

You are running this code via a .bat or .cmd file, right?

If so, probably don't have rights to write output.txt. Try writing to a different folder, e.g. >>%temp%\output.txt

Also, does this give the expected output?

@echo off
 
for /f %%i IN (unresolvedsids.txt) DO C:\Desktop\psgetsid.exe %%i

Open in new window


If so, then issue is writing output.txt as I mentioned.
Lauren QuattrocchiAuthor Commented:
the different file path did not make a difference. It creates the output file it is just empty.

For the expected output; how do i see the ouput of it if it is not writing anywhere?
NVITEnd-user supportCommented:
> ... how do i see the ouput

1. Open a CMD window where the
bat/.cmd is located

2. Type the name of the .bat/.cmd file.
Lauren QuattrocchiAuthor Commented:
There is no output when i run it that way

It is working on my computer, however it is not working in the VM environment i need to run it in, i'm thinking it might be an access issue
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.