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