I was hoping someone could help me out here. I have a csv file I'm trying to use to make new AD User accounts. The csv looks like this.
"ID","DEPT","FN","LN","BDATE","GRD"
"111111","1480","Test","HS","19980601","2018"
"222222","1479","Test","Elem","19980522","2025"
When running the below code I'm getting an error about 'Path' is null or empty. Provide an argument that is not null or empty.
Any help would be appreciated.
# Import active directory module for running AD cmdlets
Import-Module activedirectory
#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv adusers.csv
#Store report in log file in the $log variable
$log = "log.txt"
#Set Additional Variables
$Password = (ConvertTo-SecureString -AsPlainText "$User.BDATE" -Force)
$DisplayName = "$User.FN+ ' ' + $user.LN"
$SCHID = $User.DEPT
# Choose OU
Switch ($SCHID)
{
"1480" {$OU = 'OU=students,OU=users,ou=hs,dc=clasd,dc=net'}
"1479" {$OU = 'OU=students,OU=users,ou=elem,dc=clasd,dc=net'}
"1480" {$Folder = '\\hs-ss\students\hs'}
"1479" {$Folder = '\\hs-ss\students\elem'}
}
#Create Hash Table for New User Creation
$ADUsers = @{
'SamAccountName' = "$User.ID"
'UserPrincipalName' = "$User.ID + '@clasd.net'"
'GivenName' = "$User.FNAME"
'SurName' = "$User.LNAME"
'EmailAddress' = "$User.ID = '@clasd.net'"
'Path' = "$OU"
'Department' = "$User.GRD"
'Company' = "$User.DEPT"
'AccountPassword' = $Password
'ChangePasswordAtLogon' = $true
'Enabled' = $true
'DisplayName' = "$DisplayName"
'Name' = $Displayname
'Homedrive' = "Z"
'Homedirectory' = "$Folder\'$User.ID'"
}
#Call New-ADUser with the parameters Above
Foreach ($User in $ADUsers) {
New-ADUser @ADUsers}
Error code is below
New-ADUser : Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At C:\Users\jmerwin\Desktop\testUser.ps1:49 char:12 + New-ADUser @ADUsers} + ~~~~~~~~ + CategoryInfo : InvalidData: (:) [New-ADUser], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser