问题描述
我正在编写一个终止脚本,它将执行许多任务。我在使用 Get-ADUser
从AD获取经理的电子邮件地址时遇到了问题,然后可以将其插入Office 365转发电子邮件地址。我以为可以将经理的姓名放入一个变量,然后使用 Get-ADUser
将她/他的电子邮件地址放入另一个变量。不幸的是,我对PowerShell还是相当陌生,并试图自学。
I am writing a termination script that will be doing a lot of tasks. I am having issues with getting the managers email address from AD with Get-ADUser
into a variable I can then insert into Office 365 forwarding email address. I thought I could pull the Managers name into a variable and then use Get-ADUser
to pull her/his email address into another variable. Unfortunately I am fairly new to PowerShell and am trying to teach myself.
这是我的代码:
$User = Write-Host 'user ID you want to get the managers email of'
$Manger = Get-ADUser -Identity $User -Properties Manager | Select-Object @(Get-ADUser -Identity $_.Manager -Properties displayName)
推荐答案
您可以通过嵌套两个 Get-ADUser
命令来做到这一点,如下所示:
You can do this by nesting two Get-ADUser
commands as follows:
(Get-ADUser (Get-ADUser $user -Properties manager).manager -properties mail).mail
这篇关于我需要获取一个用户manager属性,使用它来获取manager对象,然后将她的mail属性放入一个变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!