Script to get displayname and homedirectory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Script to get displayname and homedirectory

#1 Post by frederixx » 06 Jun 2013 13:15

Hi,

I'm trying to get a batch file to

1: ask you for a Username
2: with the Username, it searches Active Directory for the User and gets the DisplayName & HomeDirectory
3: copy them in a text file Setup.txt
Username=Dummy
KeyfileName=\\dc01\users\dummy.txt

4: copy the Setup.txt & dummy.txt inside the HomeDirectory

I would really appreciate some pointers. I know it might be too much to ask for, but if i could get an example...

Thank you!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Script to get displayname and homedirectory

#2 Post by Squashman » 06 Jun 2013 14:06

By display name do you mean Fullname?
You can use the net user cmd to get the fullname.

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Script to get displayname and homedirectory

#3 Post by frederixx » 06 Jun 2013 14:27

Squashman wrote:By display name do you mean Fullname?
You can use the net user cmd to get the fullname.


Yes, DisplayName=full name

But my understanding of the Net user command is to modify the AD profile IE: net user /fullname:dummy2

What i really want is a script that you enter a username and it gets the full name and home directory path from the AD and copy them in my setup.txt file
Last edited by frederixx on 06 Jun 2013 14:32, edited 1 time in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Script to get displayname and homedirectory

#4 Post by Squashman » 06 Jun 2013 14:30

The net user cmd also shows the Home Directory as well.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Script to get displayname and homedirectory

#5 Post by Squashman » 06 Jun 2013 14:48

Well you could at least try it. I am not bs'ing you here. I use the net user command all the time to get the users full name.

net user Squashman /domain
net user frederixx /domain

You can then pipe that result to the find command to filter it.

net user Squashman /domain |find "Full Name"
net user Squashman /domain |find "Home Directory"

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Script to get displayname and homedirectory

#6 Post by frederixx » 07 Jun 2013 08:03

Squashman wrote:Well you could at least try it. I am not bs'ing you here. I use the net user command all the time to get the users full name.

net user Squashman /domain
net user frederixx /domain

You can then pipe that result to the find command to filter it.

net user Squashman /domain |find "Full Name"
net user Squashman /domain |find "Home Directory"


Yes, thank you Squashman, that part works.

Do you know how i can copy the result into my text file that begins with:
Username= (this is where i want the full name)
KeyfileName= (this is where i want the home dir)

Thank you!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script to get displayname and homedirectory

#7 Post by foxidrive » 07 Jun 2013 09:30

You would use a command like this to extract the information. The exact whatevers depend on what the output from the command looks like.

for /F "tokens=whatever delims=whatever" %%a in ('net user %user% /domain ^|find "Full Name"') do set name=whatever

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Script to get displayname and homedirectory

#8 Post by Dos_Probie » 07 Jun 2013 11:35

This line at end of your batch with your command/s will output a dated txt file to your C: or system drive.. 8)

Code: Select all

Your Command Here >> %systemdrive%\%computername%_INFO_%date:~-4,4%-%date:~4,2%-%date:~-7,2%.txt  

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Script to get displayname and homedirectory

#9 Post by frederixx » 07 Jun 2013 12:38

Dos_Probie wrote:This line at end of your batch with your command/s will output a dated txt file to your C: or system drive.. 8)

Code: Select all

Your Command Here >> %systemdrive%\%computername%_INFO_%date:~-4,4%-%date:~4,2%-%date:~-7,2%.txt  


That's not really what i need.

I need a script that will ask for a username. Then take that username and get some info from the Active Directory (the full name & the home directory).

Then will add the name and dir to a text file and finally copy that text file to the user's home directory.

from what i got so far:

@echo off
set /p uname=

Net User %User% /Domain
Net User %User% /Domain |find "Full name"
Net User %User% /Domain |find "Home directory"

etc..

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Script to get displayname and homedirectory

#10 Post by Dos_Probie » 07 Jun 2013 16:01

Frederixx wrote:
from what i got so far:
@echo off
set /p uname=
Net User %User% /Domain
Net User %User% /Domain |find "Full name"
Net User %User% /Domain |find "Home directory"
etc..

Well for starters your first line is incorrect, If your going to use the Set command with the /p prompt switch then you will need a variable prompt like so..

Code: Select all

@echo off
set /p User=Enter User Name:
cls
if exist "%User%:\" (goto start) else goto err
:start
<Code>

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Script to get displayname and homedirectory

#11 Post by Squashman » 08 Jun 2013 05:50

Dos_Probie,
He needs to check Active Directory for the user. You are checking the local computer with your IF command.
Frederixx, if you can wait until i get back to work on Monday I can write the script for you. Foxidrive pretty much has the base code sitting there for you.

I think we assumed you just wanted us to lead you in the right direction when you said you wanted some pointers. Now it sounds like you just want us to give you all the code.

frederixx
Posts: 9
Joined: 06 Jun 2013 13:05

Re: Script to get displayname and homedirectory

#12 Post by frederixx » 10 Jun 2013 07:37

What i had so far was an exemple of the commands needed.

Squashman, if fact, it's much harder than what i expected. I only wanted some pointers so i could figure it myself.

I got the first part which asks for a username.

Then i wanted my script to look up the AD for the full name & home dir (which you helped me with).

Then, the last part which copy the info into a text file and finally copy the text file into the home dir.

Believe me, i didn't want you to do my work but i really appreciate it.

Post Reply