Published on

Checking What AD Groups a Windows User is in and Redirecting Output to a file in Windows

Authors

Today I had to verify that a Windows user was in a specific AD group. I needed this in order to integrate with a system in the organisation. This seemed easy enough to test, simply try make a web service call to the required system -but the system was down :'(

After doing a bit of Googling I saw that the following command can be run from a Windows command prompt to get information about a user:

gpresult /V

This will give the verbose details of the current user. You can add a few more flags to get another user but unfortunately it looks like you have to be logged in as that user:

gpresult /V /USER userLogin

While running these commands I remembered yet again how much I hate the Windows command prompt. This command outputs plenty of information but most of that is lost in the Windows command prompt as the buffer size was too small. I know this should be adjustable. In this situation on Linux I would normally have just piped this output to less or a file. It turns out the syntax to redirect output to a file in Windows is identical to redirecting standard out and error in Linux:

gpresult /V /USER userLogin > yourFileHere.txt 2>&1