troubleshooting Question

Help improving AD user create script.

Avatar of Roccat
RoccatFlag for United States of America asked on
2 Comments1 Solution92 ViewsLast Modified:
I am working on a script to create an active directory user and home folder. I am looking for some tips and perhaps some help changing the input so that I can put in a username in the format of LastName,FirstName. Then it would fill in the Name = First initial Lastn Name, SamAccountName = First initial LastName, GivenName = first name, Surname = last name, DisplayName = First Name Last Name , UserPrincipalName = first name last initial

import-module activedirectory
$UserN = Read-Host -Prompt 'Input the user name'
New-ADUser -name $UserN -SamAccountName $UserN -GivenName "FirstName" -Surname "LastName" -DisplayName "Whole Name"  -UserPrincipalName (“{0}@{1}” -f $UserN,””) -Path 'OU=Staff,DC=homelab,DC=com' -AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssw0rd" -Force) -ChangePasswordAtLogon $true -Department "HTMB" -Description "Test Description" -EmailAddress "" -EmployeeID "123456" -Enabled $true -HomeDirectory "\\\Share\$UserN" -HomeDrive 'h:'
$Path = "\\\share\"

New-Item -type directory -path $path$UserN
$Acl = Get-Acl $path$userN
$Ar = New-Object"$UserN","FullControl","Allow")
Set-Acl "$path$userN" $Acl
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros