In my example I will use ExtensionAttribute4, of course you can use another one as well!
Find attached a script that using the EmployeeID:
----------------------------------------------------- # Set ExtensionAttribute4 using AD Users EmployeeID
#csv file
#employeeID,extensionAttribute4
#1482216,45837
#9999998,9999
Import-module ActiveDirectory
$Path = "C:\admin\UsersExt4.csv"
$users = Get-Content –Path $Path | ConvertFrom-CSV
$users | foreach {
$_.psobject.properties | foreach { if ($_.value -eq "") { $_.value = $null }}
$eid = $_.employeeID
$user = Get-ADUser -Filter {employeeID -eq $eid}
Set-ADUser $user.samaccountname -add @{extensionattribute4 = $_.extensionAttribute4}
}
-----------------------------------------------------
And now with the samAccountName:
-----------------------------------------------------
################################################
# File path: c:\admin\UsersExt4.csv
#
# samAccountName,extensionAttribute4
# username.1,Test12345
# username.2,Test12345
################################################
Import-module ActiveDirectory
Import-Csv C:\admin\UsersExt4.csv | ForEach-Object {Set-ADUser $_.samAccountName -Replace @{extensionAttribute4=$_.extensionAttribute4} }
-----------------------------------------------------
No comments:
Post a Comment