我需要一个现有变量来填充其他信息,该信息必须针对该变量中的每个“元素”进行解析。
这是填充我的变量的内容:
$a = Get-ADUser -Filter {Manager -eq 'User1'} -Properties Name, Department, Manager, Mail | Select Name, Department, Manager, Mail
这是我的变量
$a
的样子:@{Name=User1; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User1@mail.com} @{Name=User2; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User2@mail.com} @{Name=User3; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User3@mail.com}
What I'm trying to accomplish now is to "convert" the Managers DN to the Managers email address and add this back to the variable $a
.
My desired result would look something like this:
@{Name=User1; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User1@mail.com; ManagerMail=User1@mail.com} @{Name=User2; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User2@mail.com; ManagerMail=User1@mail.com} @{Name=User3; Department=IT; Manager=CN=User1,OU=SomeOU,DC=domain,DC=local; Mail=User3@mail.com; ManagerMail=User1@mail.com}
Right now I'm struggling to reach my goal...
I know how to resolve the Managers DN to the Managers email address (something like this):
Get-ADUser -SearchBase 'CN=User1,OU=SomeOU,DC=domain,DC=local' -Filter * -Properties Mail | Select mail
我很难从初始变量中获取特定的Manager DN,以将其解析为Managers电子邮件地址,然后再通过该变量
$a
将其重新找回。
最佳答案
$Manager = Get-ADUser -Identity 'Manager1' -Properties Mail
$a = Get-ADUser -Filter {Manager -eq 'Manager1'} -Properties Name, Department, Manager, Mail |
Select-Object -Properties Name, Department, Manager, Mail, @{Name='ManagerMail'; Expression={$Manager.Mail}}
关于powershell - 如何使用Powershell将manager-DN转换为变量内的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43499563/