Имена с отчествами у тебя в АД прописаны?
Updated: 18 October 2017, 22:38:55
вообщем тут собирать надо:
сначала получить данные из домена
разослать письмо
Updated: 18 October 2017, 22:49:19
Ну вот примерно так.
Собираем:
$OU = "OU=employees,DC=domain,DC=local"
$CSVname = "c:\scripts\CurrentStaff.csv"
Import-Module ActiveDirectory
Get-ADUser -SearchBase $OU -Filter * -Properties GivenName,Surname,EmailAddress | Select GivenName,Surname,EmailAddress | Export-Csv $csvname
рассылка
https://practical365.com/exchange-server/powershell-how-to-send-email/
https://practical365.com/exchange-server/powershell-email-message-body/
у тебя же по идее только тело надо поправить
Во, смотри - минимум переделок - файлик собрать.
# Function to create report email
function SendNotification{
$Msg = New-Object Net.Mail.MailMessage
$Smtp = New-Object Net.Mail.SmtpClient($ExchangeServer)
$Msg.From = $FromAddress
$Msg.To.Add($ToAddress)
$Msg.Subject = "Announcement: Important information about your office relocation."
$Msg.Body = $EmailBody
$Msg.IsBodyHTML = $true
$Smtp.Send($Msg)
}
# Define local Exchange server info for message relay. Ensure that any servers running this script have permission to relay.
$ExchangeServer = "yourexchange.domain.com"
$FromAddress = "Office Relocation Team <relocation@domain.com>"
# Import user list and information from .CSV file
$Users = Import-Csv UserList.csv
# Send notification to each user in the list
Foreach ($User in $Users) {
$ToAddress = $User.Email
$Name = $User.FirstName
$Level = $User.Level
$DeskNum = $User.DeskNumber
$PhoneNum = $User.PhoneNumber
$EmailBody = @"
<html>
<head>
</head>
<body>
<p>Dear $Name,</p>
<p>As you know we will be relocating to our new offices at 742 Evergreen Terrace, Springfield on July 1, 2015. This email contains important information to help you get settled as quickly as possible.</p>
<p>Your existing access card will grant you access to the new building and your desk location is as follows:</p>
<p><strong>Level:</strong> $Level<br />
<strong>Desk Number:</strong> $DeskNum<br />
<strong>Phone Number:</strong> $PhoneNum</p>
<p>Your new phone will be connected and ready for use when you arrive.</p>
<p>If you require any assistance during the move please contact the relocation helpdesk at relocation@gooselabs.net or by calling 555-555-1234</p>
<p>Regards,</p>
<p>Office Relocation Team</p>
</body>
</html>
"@
Write-Host "Sending notification to $Name ($ToAddress)" -ForegroundColor Yellow
SendNotification
}
https://www.cgoosen.com/2015/04/user-powershell-to-bulk-email-your-users/
П.С. - возможен гимор с русской кодировкой. Ну ты проверь сначала
Да-да, мне нужно срочно людей выгнать из базы, а я буду заниматься этикой и написанием нового скрипта именно под тех кого сейчас надо выгнать. А другим надо написать что у них пропуска поменять надо. А ещё вон тем надо написать чтобы они перезапустили сеансы рабочего стола. Так что не два скрипта будет а 22, если не 222