Hello,
Below an example of what you need :
$CSVFile = Import-Csv -Path "C:\temp\Temp - sashank\testph.csv" -Delimiter ","
$colObjUser = @()
foreach($line in $CSVFile) {
try {
$user = Get-ADUser -Identity $line.samaccountname -ErrorAction Stop
}
catch {
$boolModified = $false
$status = "Cannot find user"
$user = $null
}
if($line.Mobile -eq "") {
$mobile = $null
} else {
$mobile = $line.Mobile
}
if($line.telephonenumber -eq "") {
$telephone = $null
} else {
$telephone = $line.telephonenumber
}
if($user -ne $null) {
try {
$status = ""
Set-ADUser -Identity $user.SamAccountName -OfficePhone $telephone -MobilePhone $mobile -ErrorAction Stop
$boolModified = $true
}
catch {
$boolModified = $false
$status = "Cannot modify user"
}
}
$hash = @{
samaccountname = $line.samaccountname
telephonenumber = $line.telephonenumber
mobile = $line.Mobile
modified = $boolModified
status = $status
}
$objUser = New-Object PSObject -Property $hash
$colObjUser = $colObjUser + $objUser
}
Write-Output $colObjUser