query Active directory display name
Moderator: DosItHelp
query Active directory display name
Hi
Im looking to create a logon script that will query the output the user and the computer they are using.
The %username% is not enough as I cant tell from this who the user is without having to look it up.
I need the friendly name, Displayname of the user so I can output it to the 3rd colum of my csv file.
I have tried solutions I found online but none worked. Im thinking dsquery
Is their a simple way to do this??
Thanks for reading
Im looking to create a logon script that will query the output the user and the computer they are using.
The %username% is not enough as I cant tell from this who the user is without having to look it up.
I need the friendly name, Displayname of the user so I can output it to the 3rd colum of my csv file.
I have tried solutions I found online but none worked. Im thinking dsquery
Is their a simple way to do this??
Thanks for reading
Re: query Active directory display name
Hi,
At the command prompt of your computer, you can try this for starters:
the xxx.xxx.xxx.xxx is the ip address of the remote computer.
this, I beleive will help with finding who's logged in remotely.
hope that helps to start off with what you're asking.
v/r Booga73
At the command prompt of your computer, you can try this for starters:
Code: Select all
for /f "skip=1 tokens=2 delims=\" %a in ('wmic /node:xxx.xxx.xxx.xxx ComputerSystem Get UserName') do @echo %a
the xxx.xxx.xxx.xxx is the ip address of the remote computer.
this, I beleive will help with finding who's logged in remotely.
hope that helps to start off with what you're asking.
v/r Booga73
Re: query Active directory display name
Ive tried that and manually replaced the xxx.xxx.xxx.xxx with the ip address of the machine. I get the error 192.168.1.10 was unexpected at this time. I begs the question how do I get the Ip address into that line? I have looked to see if there is an enviornmental variable for ip address but couldnt find one.
This command Im using would become a batch file and then copied to all network users start up folders so it would start at boot and output the "friendly" name of the user back to a csv file on a network share
e.g. dummy command below
dsquery %username% -displayname >> \\server\share\Usernamelist.txt
Any inkling?
Thanks
This command Im using would become a batch file and then copied to all network users start up folders so it would start at boot and output the "friendly" name of the user back to a csv file on a network share
e.g. dummy command below
dsquery %username% -displayname >> \\server\share\Usernamelist.txt
Any inkling?
Thanks
Re: query Active directory display name
even if I don't replace xxx.xxx.xxx.xxx it works here.confuseis wrote:Ive tried that and manually replaced the xxx.xxx.xxx.xxx with the ip address of the machine. I get the error 192.168.1.10 was unexpected at this time. I begs the question how do I get the Ip address into that line? I have looked to see if there is an enviornmental variable for ip address but couldnt find one.
Code: Select all
Microsoft Windows XP [versie 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
>for /f "skip=1 tokens=2 delims=\" %a in ('wmic /node:xxx.xxx.xxx.xxx ComputerSystem Get UserName') do @echo %a
Knooppunt - xxx.xxx.xxx.xxx
Fout:
Code = 0x800706ba
Beschrijving = De RPC-server is niet beschikbaar.
Faciliteit = Win32
>
Code: Select all
wmic /node:xxx.xxx.xxx.xxx ComputerSystem Get UserName
this script must be run from client sideconfuseis wrote:Im looking to create a logon script that will query the output the user and the computer they are using.
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$computerName=%computerName%"
echo.$computerName=%$computerName%_
set "$name=%userName%"
echo.$name=%$name%_
set "$=" &for /f "skip=1 delims=" %%? in (
'net.EXE user !$name!'
) do if not defined $ set "$=%%~?"
::
set "$fullName=" &set "$fullName=!$:~41!" ||set "$fullName=!$name!"
echo.$fullName=%$fullName%_
pause
exit
Re: query Active directory display name
look at the NET USER command. That is what I use in all my scripts to get the person's real name.
Re: query Active directory display name
Regarding the net user command I have found
net user %username% /domain | find "display name"
I get no error so I gather that it worked however I need to output the display name that it grabs I think perhaps a third pipe?
Ill test the other suggestion's and report back
Thanks
net user %username% /domain | find "display name"
I get no error so I gather that it worked however I need to output the display name that it grabs I think perhaps a third pipe?
Ill test the other suggestion's and report back
Thanks
Re: query Active directory display name
Code: Select all
For /f "tokens=2* delims= " %%G in ('net user %username% ^/domain ^|find "Full Name"') do set fullname=%%G
Re: query Active directory display name
I think the forward slash is fine without escaping, but mainly the %username% may contain spaces or & so it would have to be quoted.
Code: Select all
For /f "tokens=2* delims= " %%G in ('net user "%username%" /domain ^|find "Full Name"') do set "fullname=%%G"
Re: query Active directory display name
So far I have net user /domain | find "display name"
this runs but gives no output
Running on its own it gives useful but to much output.
I need to grab just the full user name name / display name only & export this to a text file
Thanks
this runs but gives no output
Running on its own it gives useful but to much output.
I need to grab just the full user name name / display name only & export this to a text file
Thanks
Re: query Active directory display name
confuseis wrote:So far I have net user /domain | find "display name"
That is not the Example I provided.
Re: query Active directory display name
Ah I see the net user is enclosed. Doh
I have tried all suggestions I'm get "%%G was unexpected at this time."
Im trying to interpret the command in english
Im seeing
for the variable %%G perfrom the operation in brackets and then have %%G contain the answer/output of that operation.
I dont understand the tokens & delim but ill look it up on the weekend.
Thanks
I have tried all suggestions I'm get "%%G was unexpected at this time."
Im trying to interpret the command in english
Im seeing
for the variable %%G perfrom the operation in brackets and then have %%G contain the answer/output of that operation.
I dont understand the tokens & delim but ill look it up on the weekend.
Thanks
Re: query Active directory display name
confuseis wrote:I have tried all suggestions I'm get "%%G was unexpected at this time."
Because I assume you tried running that code from the cmd prompt.
If you read the help for the FOR command you will see this.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
Which basically means you use TWO percent symbols in a batch file and only one percent symbol at the cmd prompt.
Re: query Active directory display name
here's another option to identify who's logged in:
I've tried that here on my end at the command prompt, and returned the user name.
v/r Booga73
Code: Select all
for /f "tokens=1-2 delims=\" %g in ('whoami') do @echo %h
I've tried that here on my end at the command prompt, and returned the user name.
v/r Booga73
Re: query Active directory display name
booga73 wrote:here's another option to identify who's logged in:Code: Select all
for /f "tokens=1-2 delims=\" %g in ('whoami') do @echo %h
I've tried that here on my end at the command prompt, and returned the user name.
v/r Booga73
The OP wants the person's full name. Not the Active Directory user name.
Just realized I was using the wrong token in my code.
This is from the cmd prompt.
Code: Select all
H:\>For /f "tokens=2* delims= " %G in ('net user "%username%" /domain ^|find "Full Name"') do echo %H
H:\>echo John Smith
John Smith
Re: query Active directory display name
agh, yes, that's correct, ty; Great job on the scripting.
v/r Booga73
v/r Booga73