Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-CMDB User creates user without SMTP notification (email) #477

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 18 additions & 17 deletions smletsExchangeConnector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2910,27 +2910,28 @@ function New-CMDBUser
$username = $userEmail.Split("@")[0]
$domainAndTLD = $userEmail.Split("@")[1]
$domain = $domainAndTLD.Split(".")[0]
$newID = $domain + "_" + $username + "_SMTP"
$newID = $domain + "_" + $username + "@" + $domainAndTLD + "_SMTP(" + [guid]::NewGuid() + ')'

#create the new user
$newUser = New-SCSMObject -Class $domainUserClass -PropertyHashtable @{"domain" = "$domainAndTLD"; "username" = "$username"; "displayname" = "$userEmail"} @scsmMGMTParams -PassThru -NoCommit:$NoCommit
if (($loggingLevel -ge 1) -and ($newUser)){New-SMEXCOEvent -Source "New-CMDBUser" -EventId 0 -LogMessage "New User created in SCSM. Username: $username" -Severity "Information"}

#create the user notification projection
$userNoticeProjection = @{__CLASS = "$($domainUserClass.Name)";
__SEED = $newUser;
Notification = @{__CLASS = "$($notificationClass)";
__OBJECT = @{"ID" = $newID; "TargetAddress" = "$userEmail"; "DisplayName" = "E-mail address"; "ChannelName" = "SMTP"}
}
}

#create the user's email notification channel
$userHasNotification = New-SCSMObjectProjection -Type "$($userHasPrefProjection.Name)" -Projection $userNoticeProjection -PassThru -NoCommit:$NoCommit @scsmMGMTParams
if (($loggingLevel -ge 1) -and ($userHasNotification)){New-SMEXCOEvent -Source "New-CMDBUser" -EventId 1 -LogMessage "New User: $username successfully related to their new Notification: $userEmail" -Severity "Information"}

try {
$newUser = New-SCSMObject -Class $domainUserClass -PropertyHashtable @{"domain" = "$domainAndTLD"; "username" = "$username"; "displayname" = "$userEmail"} @scsmMGMTParams -PassThru -NoCommit:$NoCommit
if (($loggingLevel -ge 1) -and ($newUser)){New-SMEXCOEvent -Source "New-CMDBUser" -EventId 0 -LogMessage "New User created in SCSM. Username: $username" -Severity "Information"}
#create the user notification projection
$userNoticeProjection = @{__CLASS = "$($domainUserClass.Name)";
__SEED = $newUser;
Notification = @{__CLASS = "$($notificationClass)";
__OBJECT = @{"ID" = "$newID"; "TargetAddress" = "$userEmail"; "DisplayName" = "E-mail address"; "ChannelName" = "SMTP"}
}
}
#create the user's email notification channel
$userHasNotification = New-SCSMObjectProjection -Type "$($userHasPrefProjection.Name)" -Projection $userNoticeProjection -PassThru -NoCommit:$NoCommit @scsmMGMTParams
if (($loggingLevel -ge 1) -and ($userHasNotification)){New-SMEXCOEvent -Source "New-CMDBUser" -EventId 1 -LogMessage "New User: $username successfully related to their new Notification: $userEmail" -Severity "Information"}
}
catch {
New-SMEXCOEvent -Source "New-CMDBUser" -EventId 1 -LogMessage "New User: $username could not be created: $PSItem" -Severity "Error"
}
# Custom Event Handler
if ($ceScripts) { Invoke-AfterUserCreatedInCMDB }

return $newUser
}
}
Expand Down