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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
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
 
Tim BallinAuthor Commented:
That's exactly what I was looking for - thanks Kevin!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.