Hello,
I'm trying to import users from a CSV file into AD.
This is what I've got so far:
Import-Csv .\test.csv | foreach-object { New-ADUser -Title $_.UID
-Surname $_.Surname -GivenName $_.GivenName -DisplayName $_.DisplayName
-Name $_.Name -UserPrincipalName $_.UserPrincipalName -SamAccountName
$_.SamAccountName -Office $_.House -Path $_.OU -HomeDirectory
$_.HomeDirectory -HomeDrive $_.HomeDrive -ScriptPath $_.ScriptPath
-AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText
-force) -Enabled $True -ChangePasswordAtLogon $True
Add-ADGroupMember $_.Group -Members $_.SamAccountName -PassThru }
This works fine, I'm also just wondering if this is best way of doing this?
What I'd also like to do is check the CSV file for a field that has value of 1 or 0, if the value of a certain field is 1, then add another group and description to the user. This is where I'm running into trouble.
I was hoping
Where-Object {$_.<CSV field> -eq 1} | Add-ADGroupMember <group> -Members $_.SamAccountName -PassThru }
would work at the end of the script above but it doesn't, no errors, the group just isn't added to the user.
Another thing that would be nice to do with this script is to create the home drive (currently using a batch file to do this now) and also give the user modify permission.
Is it possible to do all of this with one script?
thanks