ARS Script Module - Notify edsvaSecondaryOwners after creating users works but not after copying users!

Hi!

I am about to implement different script modules in our environment. All but one litle part works as expected.

If an administrator creates a user with a special kind of employeeType, i want the process to send the information to the selected SecondaryOwners (defined as a mandatory parameter, if SecondaryOwners is empty, it´s not possible to create a user with this special kind of employeeType).

Same behaviour should be recognized within the copying of any user-object. But thats the anoying thing...it doesn´t and i am getting angry Slight smile

Active Roles SDK tells me teh following about my chosen event handler: onPreCreate/onPostCreate: Object creation or copy requested/committed

This is the error i see in the eventlog of our Active Roles Server: At line: 27 char:1. You cannot call a method on a null-valued expression.

Line 27 is marked in cyan color in my script below:

############################################################

function onPostCreate($Request)
{

$Head = "<style>"
$Head +="BODY{background-color: #FFFFFF; font-family: Arial; font-size: 13px;}"
$Head +="</style>"

if ($Request.Class -ne "user") { return }
$EmployeeType = $Request.Get("employeeType")
if ($EmployeeType -like "Extern*") {

$SAMAccountName = $Request.Get("SAMAccountName")
$DN = $Request.Get("distinguishedName")
$AccountExpiresTEMP = Get-QADUser $SAMAccountName -IncludedProperties AccountExpires | Select-Object AccountExpires #$Request.Get("AccountExpires")
$AccountExpires = $AccountExpiresTEMP.AccountExpires


#edsvaSecondaryOwners join with ";" to split later.
$TEMPSecOwners = Get-QADUser $SAMAccountName -IncludedProperties @{Name=’edsvasecondaryowners’;Expression={[string]::join(“;”, ($_.edsvasecondaryowners))}} | Select-Object @{Name=’edsvasecondaryowners’;Expression={[string]::join(“;”, ($_.edsvasecondaryowners))}}

#All values saved in an array and split into rows
[ARRAY]$SecondaryOwners = $TEMPSecOwners.edsvasecondaryowners.ToString().split(";")

$Message = "<b>Blablabla</b>"
$Message += "<br><br>"
$Message += "<i><b>SamAccountName: </b></i>" + $SAMAccountName + "<br><br>"
$Message += "<i><b>DistinguishedName: </b></i>" + $DN + "<br><br>"

if($AccountExpires -eq $NULL){

$AccountExpires = "Kein Wert festgelegt / No defined value"

}

$Message += "<i><b>Ablaufdatum: </b></i>" + $AccountExpires + "<br><br>"

#There is no Object with more than 3 SecOwners, this is why 4 is more than enough values.
$Message += "<i><b>Manager: </b></i>" + $SecondaryOwners[0] + "<br>" + $SecondaryOwners[1] + "<br>" + $SecondaryOwners[2] + "<br>" + $SecondaryOwners[3] + "<br>"

$Body = ConvertTo-Html -Head $Head -body $Message

foreach($Verantwortlich in $SecondaryOwners){

$Empfaenger = $NULL
$Empfaenger = Get-QADUser $Verantwortlich -IncludedProperties mail -ErrorAction SilentlyContinue | Select-Object mail

#Mail versenden
$SmtpServer = "changed-for-forum@loughing.com"
$from = "masterofdesaster@fantasy.de"
$subject = "Ein Benutzerkonto (Benutzer-Typ Extern) wurde erstellt!"

$smtp = New-Object system.net.mail.smtpClient($SmtpServer)
$mail = New-Object System.Net.Mail.MailMessage
$mail.From = $from
#$mail.to.Add($add)
$mail.to.Add($Empfaenger.mail)
$mail.Subject = $subject
$Mail.IsBodyHtml = $true
$mail.Body = $Body
$smtp.Send($mail)

}
}
}

#####################################################

Why does it work while creating a user but not copying? Any ideas?

Greetings @all

Mike

Parents Reply Children
No Data