Set-ADUser based on .csv file - empty attributes issue

Hi, after a few months without working with PowerShell my knowledge is slowly fading away but fortunately every time this happened before, I was able to rebuild my knowledge again and now it is the same story. However I want to optimize my simple code which populates three AD user object attributes: manager, officephone and fax with values stored in .csv file. Everything works well, but my code looks not so good in my opinion. Is there any more elegant solution?

$AddressBook = Import-CSV -Path D:\AddressBookFinal.csv

foreach($Employee in $AddressBook)

{

     if([string]::IsNullOrEmpty($Employee.ManagerUserName)) {

              Set-ADUser -Identity $Employee.EmployeeUserName -Manager $null

    } else {

              Set-ADUser -Identity $Employee.EmployeeUserName -Manager $Employee.ManagerUserName

    }

    <#similar code here for checking value of OfficePhone and Fax attributes and populating             AD attributes depending on if attribute value in .csv file is empty or not#> 

}











  • Edited by BoxiKG Monday, February 09, 2015 6:51 PM
February 9th, 2015 1:23pm

Hi BoxiKG,

If there is any other question regarding this issue, please feel free to reply this post directly so we will be notified to follow it up.

If you have any feedback on our support, please click here.

Best Regards,

Anna Wang

Free Windows Admin Tool Kit Click here and download it now
March 5th, 2015 4:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics