简体   繁体   English

如果 AD 中用户的经理字段为空,我将如何向自己发送 email?

[英]How would I send an email to myself if the user's manager field is empty in AD?

Hello I am new to PowerShell and I am trying to figure out how to send emails to user's manager.您好,我是 PowerShell 的新手,我正在尝试弄清楚如何向用户经理发送电子邮件。 In the script below I am able to send the notification if in AD,manager field is not empty, but when is black I get an error message.在下面的脚本中,如果在 AD 中,管理器字段不为空,我可以发送通知,但是当它为黑色时,我会收到一条错误消息。 How do I make it where it sends an email to myself, if the user's manager is blank?如果用户的经理是空白的,我如何让它向我自己发送 email? For some reason when I run this code, I keep getting line 233 manager email is null.出于某种原因,当我运行此代码时,我不断收到第 233 行经理 email 是 null。

code is located here: https://stackoverflow.com/a/69731370/18947133代码位于: https://stackoverflow.com/a/69731370/18947133

Import-Module ActiveDirectory
$mailprops = @{
from = "test@domainname.com
smtpserver = "server.domain.com"
bodayashtml =$true


}
$startDate = Get-Date
$enddate= $startdate.addDays(x)

$props = @{ filer = "Account expirationDate -gt '$startdate' - and AccountExpiratioDate -lt '$endDate'"

Properties ='Accountexpirationdate', 'Manager' } Properties ='Accountexpirationdate', '经理' }

$Users = Get-ADuser @props
$bodyScriptBlock = {
# Group all users by their Manager

$Users | $用户 | Group-Object Manager |组对象管理器 | ForEach-Object { ForEach对象{

# Get this Manager's email address
$managerEmail = (Get-ADUser $_.Name -Properties EmailAddress).EmailAddress

# Create a string[] with the user's Name and their Account's Expiration Date
$userList = foreach($user in $_.Group)
{
    '- {0} expires on {1}' -f $user.Name, $user.AccountExpirationDate
}

# Execute the Body scriptblock passing this user's list
$body = & $bodyScriptBlock -UserList $userList

# Set the remaing values for Mail props
$mailProps.To = $managerEmail
$mailProps.Subject = "Account Expiration Notification for Managees" # ??? No idea what to put here
$mailProps.Body = $body

# Send the email with the list of users
Send-MailMessage @mailProps

Have you tried你有没有尝试过

if ($null -eq $ManagerEmail)
   {$ManagerEmail = "yourEmail@domain.com"}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何提取AD用户电子邮件,然后将其传递给Function以使用该ADuser电子邮件发送电子邮件 - How to pull AD user email then pass it to Function to send email using that ADuser email 获取 AD 用户的经理和与用户经理关联的主要组 - Get AD users’ manager and primary group that is associated with a user's manager 获取广告用户的管理员,并将其输入到表的列中 - Get an AD user's manager and input it into column of table 如何将用户输入的用户名和密码与AD组进行比较? - How would I compare the username and password entered by the user against an AD group? 从组中提取AD记录属性,但也需要经理的电子邮件地址 - Extracting AD records attributes from a group but need manager's email address as well Powershell 命令在标题字段中替换 AD 用户的标题不起作用? - Powershell command to replace AD user's title in title field not working? 我如何从电子邮件地址的输入文件中获取 sAMAccountName 和其他用户属性? - How would I get sAMAccountName and other user attributes from an input file of email addresses? 在 Azure AD 中,如何通过 PowerShell(例如 Set-AzureADUser 和 Get-AzureADUser)设置和读取用户的主要电子邮件? - In Azure AD, how to set and read a user's primary email through PowerShell (e.g. Set-AzureADUser and Get-AzureADUser)? 如何使用 Powershell 提取 AD 中经理的多个属性? - How can I extract multiple attributes of manager in AD using Powershell? 通过电子邮件查找 AD 用户 - Find AD-user by Email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM