Score:0

Create User active directory Bulk and home folder for user but folder Not Created

cn flag

all

I am trying to create a user with Active Directory and home folder automatically using bulk files and csv but when the user is done I check the user profile it redirects every user's home folder but I check the directory folder is not created automatically, can you solve my problem?

Import-Module activedirectory
  
#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\blablabla.csv

#Loop through each row containing user details in the CSV file 
foreach ($User in $ADUsers)
{
    #Read user data from each field in each row and assign the data to a variable as below
        
    $Username   = $User.username
    $Password   = $User.password
    $Firstname  = $User.firstname
    $Lastname   = $User.lastname
    $OU         = $User.ou #This field refers to the OU the user account is to be created in
    $Password = $User.Password

    #Check to see if the user already exists in AD
    if (Get-ADUser -F {SamAccountName -eq $Username})
    {
         #If user does exist, give a warning
         Write-Warning "A user account with username $Username already exist in Active Directory."
    }
    else
    {
        #User does not exist then proceed to create the new user account
        
        #Account will be created in the OU provided by the $OU variable read from the CSV file
        New-ADUser `
            -SamAccountName $Username `
            -UserPrincipalName "[email protected]" `
            -Name "$Firstname $Lastname" `
            -GivenName $Firstname `
            -Surname $Lastname `
            -Enabled $True `
            -DisplayName "$Firstname $Lastname" `
            -Path $OU `
            -AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $False `
            -HomeDirectory "\\FPEB2019\William\$($Lastname +" "+ $Username)" -HomeDrive "Z:" `   
    }
}
```[result][1]


  [1]: https://i.stack.imgur.com/Vm896.png
djdomi avatar
za flag
why not posting the results as text in here?
bjoster avatar
cn flag
The home directory ist created by the *Client*, while it is creating its profile. It is not created by a DC.
Score:0
cn flag

Verify that the value of the parameter HomeDirectory "\\FPEB2019\William\$($Lastname +" "+ $Username)" evaluates to the correct and intended value, be sure that you do not need to use an escape sequence for the double quotation mark in order to concatenate the strings to get the folder name. Check that you are not using invalid characters in any of the variables. Have you try without the space between the last name and the username?

You can add as part of your foreach cycle a command in order to create the desired folder in the desired UNC path

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.