AD Powershell Script to Create User

I pulled this off Technet and I'm a little confused as to the purpose of line 4 "$homepath".  How does it differ from line 7 "$pathToShare"?  I'm just not sure how to customize this part of the script.

function CreateHomeDir
{
   Param([string]$user)
   $homepath="X:\Users\$user"
   $shareName="$user$"
   $Type=0
   $pathToShare="\\acmenet01\f$\Users\$user"
   New-Item -type directory -path $pathToShare|Out-Null
   $WMI=[wmiClass]"\\acmenet01\root\cimV2:Win32_Share" 
   $WMI.Create($homepath,$shareName,$Type)|Out-Null
}

Open in new window

Tim BallinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
$homepath is the mapped drive.  

$pathtoshare is the UNC path where the directory is being created
New-Item -type directory -path $pathToShare|Out-Null

Open in new window

0
MaheshArchitectCommented:
Homepath resembles to root share for home directory - constant

$pathtoshare is actual user folder path under root share and this will be created by script under root share

To map user home drive, they are using "wmi.create" which is nothing but concatenating of homepath and sharename variables
0
Tim BallinAuthor Commented:
Thanks for the reply Dustin.  I'm still a little confused regarding the $homepath / mapped drive question.  Is there an equivalent field on the user property sheet in ADUC?  Like under the "Profile" tab for example?  (Like the Home folder section under the Profile tab)
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

MaheshArchitectCommented:
your script is not working?

or what is problem?
0
Tim BallinAuthor Commented:
Mahesh - I'm trying to customize this script I found online, but I'm not exactly sure what I need to do to customize this part.
0
Kevin StanushApplication DeveloperCommented:
As others have said, the line:

$pathToShare="\\acmenet01\f$\Users\$user"

Is specifying where you want the user home directory share created.  This script creates a SHARED home directory, so each user gets their own unique share, not just a directory under a single shared folder.

When you create users with a script, you have to create the directory yourself, and then (optionally) share it out, which is what this script is doing.  But to create a share, you have to tell the WMI command where you want it created on the server, then you can put it into the user object in AD.  The location of the share is not stored in AD, its part of the newly created share, ie on Share Properties.
0
Tim BallinAuthor Commented:
I think I'm pretty clear on the $pathtoshare part now...  What confusion remains though is with the $homepath.  What does that do?
0
Kevin StanushApplication DeveloperCommented:
$homepath is the physical drive and directory on the server where the share is stored.  Its wierd that its an X: drive instead of something like C: or D: but that drive/directory combo must be a legal path on the remote server.  Not a mapped drive, but the actual drive letter as understood by the remote server.  

Read here for an example:

https://msdn.microsoft.com/en-us/library/aa389393(v=vs.85).aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tim BallinAuthor Commented:
That's exactly what I was looking for - thanks Kevin!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.