Import AD Info in Bulk

Hi All. I am very new to PowerShell. What I am trying to accomplish is to get bulk information updated in AD from other sources. I have a CSV/excel spreadsheet formatted below:

ADUsers UserprincipalName Name GivenName Surname Enabled DisplayName Path City Company State StreetAddress OfficePhone MobilePhone EmailAddress Title Department Discription
ttestADSYNC ttestADSYNC@rmseq.com Test TEST Test TEST TRUE Test T. TEST CN=Test T. TEST,OU=test,DC=,DC=com Test City TEST TT 5 Test. 31 W 999-999-9999 999-999-9999 ttestADSYNC@test.com TEST - TEST ACCOUNT IT Test City

Below is my script:

### Update AD Users
# Import active directory module for running AD cmdlets
Import-Module activedirectory
 
#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\Users\mwaskosky\Downloads\Projects\UpdateADusers5-7-2021importtest.csv

#Loop through each row containing user details in the CSV file 
foreach ($User in $ADUsers)
{
    #Read user data from each field in each row and assign the data to a variable as below

    
   ### -Remove - Add - Replace - Clear @{Attribute1LDAPDisplayName=value1, value2, ...; Attribute2LDAPDisplayName=value1, value2, ...; AttributeNLDAPDisplayName=value1, value2, ...}
   ### [-Replace <Hashtable>]
 Set-ADUser -Replace `
            -Name "$($User.Firstname)$($User.Lastname)"`
            -GivenName $($User.GivenName) `
            -Surname $($User.Surname) `
            -DisplayName "$($User.DisplayName)" `
            -Path $($User.Path) `
            -City $($User.City) `
            -Company $($User.Company) `
            -State $($User.State) `
            -StreetAddress $($User.streetaddress) `
            -OfficePhone $($User.OfficePhone) `
            -MobliePhone $($User.MobilePhone) `
            -EmailAddress $($User.email) `
            -Title $($User.jobtitle) `
            -Department $($User.Department) `
            -Discription $($User.Discription) `
   }

I am not sure what do do next I have been working on this for a long time now and I have tried many different things. And I think that I am close.

Mwaskosky,

welcome to the forums.

Before we proceed - please go back and edit your existing post to correct the formatting of the code. Simply select your code and hit the </> icon on the edit bar.

Thanks in advance.

Regardless of that: What’s your actual question?

Done added the what is my script.

I am looking to be able to import in Bulk existing User Accounts in AD that are users in AD I just want to update Location, Cell Phone, Email and such for each AD user we have in AD. I hope that helps.

Great. Thanks.

OK. But what is your question? Is there something not workling as expected? Do you get error messages? If the answer is “yes” you should post them here as well (also formatted as code please :wink: )

Regardless of that you should read about splatting. That’ll make your code a lot easier to read without using crappy backticks

Yes below is the error I am getting:

Set-ADUser : Cannot bind parameter 'Replace'. Cannot convert the "-Name" value of type "System.String" to type "System.Collections.Hashtable".
At C:\Users\mwaskosky\Documents\PowerShell PS1\RMS\UpdateAD User Accounts.ps1:16 char:13
+  Set-ADUser -Replace `
+             ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser

So you’ve got the error that something is wrong with the -Replace parameter you used. What do you do next? :wink:

I’d recommend to (re-)read the help for Set-ADUser …

… especially the examples 3, 4 and 6 and the chapter about the -Replace parameter.

I’d think about if I need the -Replace parameter at all. :wink: :wink: … and I’d consider using the parameter -Identity to identify the user I want to change. :wink:

Thanks I will try to change it to Identity.

Hmmm … that doesn’t sound like you’ve got what I wanted to explain to you. :smirk: :wink:

OK. Try to solve it yourself and if it does not work come back please. :wink:

Olaf set you on the right track. No way to test, but maybe try something like this:

 Set-ADUser $user.SamAccountName -Replace @{
	'Name' = "$($User.Firstname)$($User.Lastname)"
	'GivenName' = $($User.GivenName)
	'Surname' = $($User.Surname)
	'DisplayName' = "$($User.DisplayName)"
	'Path' = $($User.Path)
	'City' = $($User.City)
	'Company' = $($User.Company)
	'State' = $($User.State)
	'StreetAddress' = $($User.streetaddress)
	'OfficePhone' = $($User.OfficePhone)
	'MobliePhone' = $($User.MobilePhone)
	'EmailAddress' = $($User.email)
	'Title' = $($User.jobtitle)
	'Department' = $($User.Department)
	'Discription' = $($User.Discription)
}

Thanks guys I am getting closer I think. Does my excel spreadsheet have to be Comma delimited CSV or can it be in different rows and columns and saved as a CSV?

It should be whatever you define suitable for your “workflow”. In the easiest case it is a proper CSV file with any delimiter you like.

But there are even ways to handle native Excel files as well with the great module from Doug Finke ImportExcel.

Thank you so very much.