RE: Simple AD shell script - discover usernames



I'm trying to do something similar - except the reverse - i'm trying to get
the full name of a user based on their username using dsquery (or any other
AD tool possible).

thanks.

"Martin Jones" wrote:

> Hi,
> I'm trying to create a script that takes a txt list of users full names, and
> does a dsquery to find their username.
> Txt file layout :
> smith, john
> jones, taffy
> ...etc
>
> Script:
>
> REM Pass Users Full Name to this batch (format: surname, firstname)
> REM First create input text file: C:\Temp\userlist.txt
>
>
> Rem **** Clear temp variables
>
> set FullName=
>
>
> Rem **** Extract Name
>
> For /f "tokens=2 delims=[" %%a in ('Findstr /I /C:"[" C:\Temp\userlist.txt')
> do (set mess=%%a)
> For /f "tokens=1 delims=]" %%b in ("%mess%") do (set FullName=%%b)
>
>
>
>
> Rem **** Check if Output file exists and create if not
>
> IF EXIST C:\temp\output.txt Goto Output
>
> Echo Full Name,Username >C:\temp\output.txt
>
>
>
>
> :Output
>
> Rem **** Run Dsquery
>
> dsquery user -name "%FullName%" | dsget samid >>C:\Temp\output.TXT
>
> --------------------------------------------------------------------------
>
> Script is salvaged from an old IP discovery script I part-wrote a while ago.
> Obviously its not working, and I suspect its poor use of tokens/delims.
>
> Any ideas/help very welcome.
> Thanks in advance.
.



Relevant Pages

  • Re: Simple AD shell script - discover usernames
    ... > I'm trying to create a script that takes a txt list of users full names, ... > jones, taffy ... > REM First create input text file: C:\Temp\userlist.txt ... > set FullName= ...
    (microsoft.public.windows.server.scripting)
  • Re: Why does this fail?
    ... Martin Jones wrote: ... > Running a simple script, ... > Where %%a is a findstr variable that contains the username ... Microsoft MVP Scripting ...
    (microsoft.public.scripting.vbscript)
  • Simple AD shell script - discover usernames
    ... I'm trying to create a script that takes a txt list of users full names, ... Txt file layout: ... set FullName= ... IF EXIST C:\temp\output.txt Goto Output ...
    (microsoft.public.windows.server.scripting)

Loading