Asked by:
Script for Updating the Bulk info for enable users in AD from CSV file

General discussion
-
This codes it working for me and it is updating the information of users in AD.
But I need:
1 - how can I do this update just for Enable users
2 - how can I use manager name in Excell like: Firstname Lastname NOT theire username
Declare file path and sheet name
$credential=Get-Credential
[threading.thread]::CurrentThread.CurrentCulture = 'en-US'
$file = "Path\UpdateUsers.xlsx"
#Create an Excel.Application instance and open that file
$Excelobject = New-Object -ComObject Excel.Application
$Workbook = $Excelobject.Workbooks.Open($file)
$sheetName = "Sheet1"
$sheet = $Workbook.Worksheets.Item($sheetName)
#$objExcel.Visible=$true
#Count max row
$rowMax = ($sheet.UsedRange.Rows).count
#Count max column
$colMax = ($sheet.UsedRange.Columns).count
$hash = @{}
$server = "Server IP"
#Specify starting positions
$row,$col = 1,1
$updatedCount = 0
#loop for rows
for ($i=1; $i -le $rowMax-1; $i++)
{
#loop for columns
for($c=0; $c -le $colMax-1; $c++)
{
#Get all columns values to a hash
$hash += @{$sheet.Cells.Item($row,$col+$c).text = $sheet.Cells.Item($row+$i,$col+$c).text}
}
#Create an object and assign hash keys as object property
$Object = New-Object -TypeName PSObject -Property $hash
#Get User via SamAccountname
$user = Get-ADUser -Filter "SamAccountName -eq '$($Object.UserName)'" -Server $server -Credential $credential
#Set Users attribute with matched object attribute
$user | Set-ADUser -GivenName $Object.GivenName `
-Surname $Object.SN `
-DisplayName $Object.Displayname `
-OfficePhone $Object.PhoneNumber `
-EmailAddress $Object.email `
-Description $Object.Description `
-City $Object.City `
-Country $Object.Country `
-Office $Object.Office `
-Title $Object.Title `
-Company $Object.Company `
-Department $Object.Department `
-Manager $Object.Manager `
-EmployeeID $Object.employeeID `
-Mobile $Object.Mobile `
-Fax $Object.Fax
#If you want to edit Object common name, you can remove enable two lines below.
#$userguid = $user.ObjectGUID.Guid
#$user | Rename-ADObject -NewName $Object.DisplayName -Server $server -Credential $credential
$hash = @{}
Write-Host $User.Name "- User attributes have been updated." -ForegroundColor Yellow
Start-Sleep -s 1
$updatedCount += 1
}
Write-Host $updatedCount "Users have been updated" -ForegroundColor Green
#close excel file
$Excelobject.quit()
- Edited by Navid Yousefi Friday, October 18, 2019 3:41 PM
- Changed type Navid Yousefi Friday, October 18, 2019 4:36 PM
- Changed type Navid Yousefi Friday, October 18, 2019 4:57 PM
- Changed type Bill_Stewart Tuesday, April 14, 2020 4:56 PM
- Moved by Bill_Stewart Tuesday, April 14, 2020 4:56 PM This is not "scripts on demand"
Friday, October 18, 2019 3:40 PM
All replies
-
But I need:
Please read this first:
This forum is for scripting questions rather than script requests
I would advise to ask whoever wrote the original script to update it for you.
-- Bill Stewart [Bill_Stewart]
Friday, October 18, 2019 4:02 PM -
Thanks for your advice.Friday, October 18, 2019 4:57 PM