Script to get displayname and homedirectory
Moderator: DosItHelp
Script to get displayname and homedirectory
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!
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!
Re: Script to get displayname and homedirectory
By display name do you mean Fullname?
You can use the net user cmd to get the fullname.
You can use the net user cmd to get the fullname.
Re: Script to get displayname and homedirectory
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.
Re: Script to get displayname and homedirectory
The net user cmd also shows the Home Directory as well.
Re: Script to get displayname and homedirectory
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"
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"
Re: Script to get displayname and homedirectory
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!
Re: Script to get displayname and homedirectory
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
for /F "tokens=whatever delims=whatever" %%a in ('net user %user% /domain ^|find "Full Name"') do set name=whatever
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Script to get displayname and homedirectory
This line at end of your batch with your command/s will output a dated txt file to your C: or system drive..
Code: Select all
Your Command Here >> %systemdrive%\%computername%_INFO_%date:~-4,4%-%date:~4,2%-%date:~-7,2%.txt
Re: Script to get displayname and homedirectory
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..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..
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Script to get displayname and homedirectory
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..
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>
Re: Script to get displayname and homedirectory
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.
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.
Re: Script to get displayname and homedirectory
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.
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.