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:
### 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.
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.
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.
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 )
Regardless of that you should read about splatting. That’ll make your code a lot easier to read without using crappy backticks
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
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?