Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

AD User Importing Script Adjustments

$
0
0

Hello All, and thanks if advance for any help.

I am working on this script to import users and need some help to figure out the remaining hurdles.
I will take one hurdle at a time.
In the script I am trying set the HomeDirectory so that the home folder name will match the users assigned username as the script is run and folder created.
Currently I just have %username% as a place holder till the needed changes are in place.

pre

$users = Import-Csv -Delimiter "," -Path ".\importtest2.csv"
$pass = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
$ou = "OU=aaa,OU=bbb,DC=ccc,DC=windhamsd,DC=org"

foreach ($user in $users)
{
#define a New-ADUser
$hash = @{
Name = "$($user.firstname) $($user.middlename) $($user.lastname)"
Displayname = "$($user.firstname) $($user.middlename) $($user.lastname)"
Path = $ou
Surname = $user.lastname
GivenName = $user.firstname
Initials = $user.middlename
Samaccountname = "$($user.firstname[0])$($user.middlename[0])$($user.lastname)"
UserPrincipalName = "$($user.firstname[0])$($user.middlename[0])$($user.lastname)@windhamsd.org"
Email = $user.emailaddr
Office = $user.schoolid
Description = $user.description
Homedrive = "H:"
HomeDirectory = ('\\servername.ccc.windhamsd.org\sharedfolder\%username%')
AccountPassword = $pass
Enabled = $True
ChangePasswordAtLogon = $True
}

New-ADUser @hash -PassThru
}

/pre


Viewing all articles
Browse latest Browse all 13067

Trending Articles