powershell script for set some ad attributes
in data - csv file
#by alex
import-module activedirectory
clear
$path = 'c:\scripts\users-info-update.csv'
$csv = Import-Csv $path
foreach($usercsv in $csv){
$usercsv.DisplayName
if($usercsv.mobile){
Set-ADUser $usercsv.sAMAccountName -mobile $usercsv.mobile
"set mobile "+$usercsv.mobile
}
if($usercsv.description){
Set-ADUser $usercsv.sAMAccountName -Description $usercsv.description
"set description "+ $usercsv.description
}
if($usercsv.title){
Set-ADUser $usercsv.sAMAccountName -Title $usercsv.title
"set title "+$usercsv.title
}
Set-ADUser $usercsv.sAMAccountName -Company "Company"
if($usercsv.ipPhone){
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'ipPhone'=[string]$usercsv.ipPhone}
"add ipPhone "+$usercsv.ipPhone
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'ipPhone'=[string]$usercsv.ipPhone}
"replace ipPhone "+$usercsv.ipPhone
}
}
if($usercsv.telephoneNumber){
Set-ADUser $usercsv.sAMAccountName -OfficePhone $usercsv.telephoneNumber
"replace telephoneNumber "+$usercsv.telephoneNumber
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'HomePhone'=[string]$usercsv.telephoneNumber}
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'HomePhone'=[string]$usercsv.telephoneNumber}
}
}
if($usercsv.facsimileTelephoneNumber){
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'facsimileTelephoneNumber'=[string]$usercsv.facsimileTelephoneNumber}
"add facsimileTelephoneNumber "+$usercsv.facsimileTelephoneNumber
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'facsimileTelephoneNumber'=[string]$usercsv.facsimileTelephoneNumber}
"replace facsimileTelephoneNumber"+$usercsv.facsimileTelephoneNumber
}
}
}
in data - csv file
#by alex
import-module activedirectory
clear
$path = 'c:\scripts\users-info-update.csv'
$csv = Import-Csv $path
foreach($usercsv in $csv){
$usercsv.DisplayName
if($usercsv.mobile){
Set-ADUser $usercsv.sAMAccountName -mobile $usercsv.mobile
"set mobile "+$usercsv.mobile
}
if($usercsv.description){
Set-ADUser $usercsv.sAMAccountName -Description $usercsv.description
"set description "+ $usercsv.description
}
if($usercsv.title){
Set-ADUser $usercsv.sAMAccountName -Title $usercsv.title
"set title "+$usercsv.title
}
Set-ADUser $usercsv.sAMAccountName -Company "Company"
if($usercsv.ipPhone){
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'ipPhone'=[string]$usercsv.ipPhone}
"add ipPhone "+$usercsv.ipPhone
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'ipPhone'=[string]$usercsv.ipPhone}
"replace ipPhone "+$usercsv.ipPhone
}
}
if($usercsv.telephoneNumber){
Set-ADUser $usercsv.sAMAccountName -OfficePhone $usercsv.telephoneNumber
"replace telephoneNumber "+$usercsv.telephoneNumber
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'HomePhone'=[string]$usercsv.telephoneNumber}
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'HomePhone'=[string]$usercsv.telephoneNumber}
}
}
if($usercsv.facsimileTelephoneNumber){
try{
Set-ADUser $usercsv.sAMAccountName -Add @{'facsimileTelephoneNumber'=[string]$usercsv.facsimileTelephoneNumber}
"add facsimileTelephoneNumber "+$usercsv.facsimileTelephoneNumber
}
catch{
Set-ADUser $usercsv.sAMAccountName -Replace @{'facsimileTelephoneNumber'=[string]$usercsv.facsimileTelephoneNumber}
"replace facsimileTelephoneNumber"+$usercsv.facsimileTelephoneNumber
}
}
}