Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Newbie - Needs help with AD import from CSV with adding security group to user

$
0
0

Hello, ive been given the task at work to speed up the new user creation into AD at my local NHS Trust we have 3000+ users.

Powershell is new to me, ive created HTA's and made a few websites etc before so Ive been set the task.

I always try first before asking, and now im stuck!

Ive managed to create a script that works somehow that does import from a csv file.

But now i need to add some Security Groups to the users member of tab.

Can this all be done in one script and 1 csv file?, so the script creates the user and adds the required groups all together.

Ive been looking at the Add-ADGroupMember but not sure where in the script to put it or what comes after it.

Here is my script, im sorry if its bad, (it does work though!) ive only been looking at powershell for a few weeks

 

I'm using a Test Domain at present which ive called GMAIN.nhs.uk on  server 2008r2

Import-module activedirectory
Import-Csv .\users.csv | foreach-object {
$domain='@GMAIN.nhs.uk'
$userprincipalname=$_.cn+"."+$_.sn+$domain

New-ADUser -Name $_.name `
-SamAccountName $_.sAMAccountName `
-UserPrincipalName $userprincipalname `
-DisplayName $_.name `
-GivenName $_.cn `
-SurName $_.sn `
-Description $_.Description `
-Department $_.Department `
-Company $_.Company `
-Path "OU=GMAIN Users,DC=GMAIN,DC=nhs,DC=uk" `
-AccountPassword (ConvertTo-SecureString "Password1!;" -AsPlainText -force) `
-Enabled $True `
-ChangePasswordAtLogon $True `
-PassThru}

 

If any help or advice can be given if i need to use the Add-ADGroupMember in the script would be great.

 

Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles