Hello,
Help my in xml file for Scripting Agent
We have not been able to solve the problem for several days now.
where is the error here?
<?xml version="1.0" encoding="utf-8" ?>
<Configuration version="1.0">
<Feature Name="WelcomeEmail" Cmdlets="New-Mailbox,Enable-Mailbox">
<ApiCall Name="OnComplete">
if($succeeded) {
# Waiting for synchronization after mailbox has been created.
Set-ADServerSettings -ViewEntireForest $true
Start-Sleep -s 10
# New-Mailbox triggered. Taking SamAccountName parameter.
if ($provisioningHandler.UserSpecifiedParameters.Contains("SamAccountName") -eq $true) {
$UsrSamAccountName = $provisioningHandler.UserSpecifiedParameters["SamAccountName"]
$UsrAlias = (Get-Mailbox -Filter {SamAccountName -eq $UsrSamAccountName}).Alias.ToString()
}
# Enable-Mailbox triggered. Taking Identity parameter, this is the only one avalaible in this case.
if ($provisioningHandler.UserSpecifiedParameters.Contains("Identity") -eq $true) {
$UsrIdentity = $provisioningHandler.UserSpecifiedParameters["Identity"].ToString()
$UsrAlias = (Get-Mailbox -Identity $UsrIdentity).Alias.ToString()
}
chcp 65001
$smtpServer = "srvEXCH.contoso.com"
$from = "******@contoso.com"
$searchOU = "OU=etest,OU=Contoso org structure,OU=Contoso Organization,DC=contoso,DC=com"
$hourAgo = (Get-Date).AddHours(-1)
$employees = Get-ADUser -SearchBase $searchOU -Filter "whenCreated -ge '$hourAgo'" -Properties EmailAddress
$existingEmployees = Get-Content -Path "C:\employees.txt"
$subject = "Добро пожаловать в нашу компанию!"
$body = "<span style='font-family: Times New Roman; font-size: 16pt; font-weight: bold; font-style: italic;'>Уважаемый коллега!<br>
Добро пожаловать в АО «Contoso»!<br>
Надеемся, что работа в нашей компании принесет Вам полезный опыт, новые впечатления и удовольствие от общения с коллективом!<br>
Для более быстрой адаптации рекомендуем пройти по нижеследующей ссылке и ознакомиться с Адаптационным курсом, разработанным специально для новых работников <a href='https://adaptaciya.contoso.com/'>https://adaptaciya.contoso.com/</a><br>
В случае возникновения вопросов по содержанию курса, просим обращаться к представителю ДУЧР, Имя Фамилия (<a href='mailto:******@contoso.com'>******@contoso.com</a>, 78-78-78)<br>
В случае возникновения вопросов технического характера (ссылка не открывается и др.), просим обращаться в Единый контакт-центр по номеру 9999 или на email <a href='mailto:******@contoso.com'>******@contoso.com</a>.<br>
Удачи Вам!
<br>
тел. 8787</span>"
Send-MailMessage -SmtpServer $smtpServer -From $from -To $to -Subject $subject -BodyAsHtml $body -Encoding utf8
foreach ($employee in $employees) {
if ($existingEmployees -notcontains $employee.EmailAddress) {
$to = $employee.EmailAddress
Send-MailMessage -SmtpServer $smtpServer -From $from -To $to -Subject $subject -BodyAsHtml $body -Encoding utf8
Add-Content -Path "C:\employees.txt" -Value $to
}
}
}
# Clearing variables. Each one in its own line in order to prevent error messages from being shown on EMC.
if ($UsrAlias) { Remove-Variable UsrAlias }
if ($UsrAddr) { Remove-Variable UsrAddr }
if ($UsrOU) { Remove-Variable UsrOU }
if ($UsrMsg) { Remove-Variable UsrMsg }
if ($UsrIdentity) { Remove-Variable UsrIdentity }
if ($UsrSamAccountName) { Remove-Variable UsrSamAccountName }
}
</ApiCall>
</Feature>
</Configuration>