AdhocAdam / smletsexchangeconnector

SMLets PowerShell based Exchange Connector for controlling Microsoft System Center Service Manager 2016+
https://adhocadam.github.io/smletsexchangeconnector/
GNU General Public License v3.0
29 stars 19 forks source link

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

Open pwahlmueller opened 1 year ago

pwahlmueller commented 1 year ago
  1. Since the SMTP notification was not in all cases unique, I added a. the domain b. a guid (to be absolute on the safe side)

  2. And I added error handling in case, somthing still fails.

Here in addition the scenario, which fails:

  1. Send email with patrick@mydomain.com which is not yet in CMDB -> notification newid gets patrick_SMTP
  2. Send email with patrick@myNEWdomain.com which is not yet in CMDB ->notification newid gets patrick_SMTP -> fails adding notification
AdhocAdam commented 1 year ago

I feel like you are onto something here by forcing the ID to be unique with a GUID. But the thing is, I can't reproduce the scenario you're referring to above as the ID I'm seeing is still unique with the domain name + username.

I copied the New-CMDBUser function out, introduced a Write-Host for the $newID variable, and then ran it with both examples. In which case, that arguably becomes a question of "how is the email not being found which leads to incorrectly calling New-CMDBUser." I'm genuinely not sure if that's the issue as this whole thing has been hard to pin down. The last thing I recall in this space was the update made to Get-SCSMUserByEmailAddress wherein SMLets was incorrectly evaluating hyphens in email addresses.

result

In any case, the only way I can produce an error is if I don't delete those users from SCSM, and then run the example again. In which case, duplicate users are created with empty Notification Channels.

Note: Ignore the Problems 1 in the above screenshot. I have a few things open 😄

pwahlmueller commented 11 months ago

You are completly right, the id would be unique with domain name + username. But in the actual script only the username was used, which causes the issue. I wonder that you can add both users with the actual script - could you? The main reason to add the guid was, that I'm absolut sure the id will be unique in the prod env of the customer.

But I can do a script in my test environment to double check it and provide it here, if this helps.

AdhocAdam commented 11 months ago

But in the actual script only the username was used, which causes the issue

Are you referring to the following line in New-CMDBUser? or somewhere else?

https://github.com/AdhocAdam/smletsexchangeconnector/blob/02be0b1aed028647848c982e19ae5779c7596822/smletsExchangeConnector.ps1#L2916C9-L2916C209

I wonder that you can add both users with the actual script - could you?

Sure. So add the two users via script and then?

The main reason to add the guid was, that I'm absolut sure the id will be unique in the prod env of the customer. But I can do a script in my test environment to double check it and provide it here, if this helps.

Like I said, I am strongly inclined to agree with you here on this change. I just want to see it for myself is all 😁 but if you can validate that's helpful as well 👍