Здесь действительно не так много вопросов в этом вопросе.Get-UserActiveManage
, вероятно, более удачно назвали бы Get-Employee
.Естественно, я не проверял это, но что-то в этом роде может работать.Продумайте шаги для каждого условия цикла.
$employee = $item
$manager = $null
while (($item.WorkStatusTypeCd -ne $null) -and ($item.WorkStatusTypeCd -eq "ACTIVE")) {
$managerId = $item.ManagerId
$item = Get-UserActiveManager -searchType ID -searchString $managerId
if (($item.WorkStatusTypeCd -ne $null) -and ($item.WorkStatusTypeCd -eq 'ACTIVE')) {
### This is the manager.
$manager = $item
} elseif ($item.ManagerId -eq $null) {
### The end. No manager can be found.
}
}
'{0} is the manager of {1}' -f $($manager.EmployeeId, $employee.EmployeeId)