Open AdhocAdam opened 1 year ago
I've been doing some extensive testing of this proposed change @alexaxb. I had a question/scenario that I'm not sure needs to be handled, but seems worth bringing up if we're here working on this. For the sake of example, let's imagine a run of the connector processing a single email.
If the connector runs again looking for the same address, it should correctly be able to identify the user via Get-SCSMUserByEmailAddress and thus, never engage New-CMDBUser. I point this out as in my testing, if I try to create the user again using the proposed changes in this PR it throws an error that isn't handled because the Notification Channel object already exists e.g. "New-SCSMObjectProjection : A discovery data item was rejected because the item has already been inserted by another user or process." This is probably okay, because it doesn't seem like a path that could ever be logically executed in the connector.
But this led me to a question, have you ever experienced a scenario wherein the User object exists, the Notification Channel object exists/is related, but the Notification Channel does not have the Email/Target address set? Because if so, it means the above scenario could be executed and thus, should be handled.
I would say no. Can't remember that I've seen a user with an Notification Channel with empty address. If the user is missing an address, the usual would be that the Notification Channel object would also be missing.
We experience the same issue. We can reproduce it:
Can you reproduce on demand @pwahlmueller? If so, it'd be great to get some PowerShell debugging events by running the connector manually (ISE or VS Code) and see what (if any) kind of errors are thrown.
It reproduces every time, but don' exactly know why. When I copy the "New-CMDBUser" code to a script only generating user + email, it works as it should. I'll try the debugging this afternoon.
We use the connector in System Center Orchestrator.
So this is the error message. I think I have the solution. Will provide it.
New-SCSMObjectProjection : A discovery data item was rejected because the item is already bound to another Membership relationship.
At D:\_SCOWorkingDir\smlets connector ursprung.ps1:2795 char:32
+ ... ification = New-SCSMObjectProjection -Type "$($userHasPrefProjection. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Enter...bjectProjection:EnterpriseManagementObjectProjection) [New-SCSMObjectProjection], DiscoveryDataLifetimeDependencyException
+ FullyQualifiedErrorId : projection commit failure,SMLets.NewSCSMObjectProjectionCommand
So think I'd to add a new PR for my changes, see https://github.com/AdhocAdam/smletsexchangeconnector/pull/477
If you want to do
It is recommended to use the verb Set for the function instead of new.
Describe the change
New-CMDBUser is called when an e-mail address cannot be found in SCSM, but if the username/domain combo already exists in SCSM but without the mail address the user creation will fail without an error message. This has happened to me a couple of times now, and is kind of hard to detect.
Added a simple check to see if the user object already exists before creation, and if the creation should fail for some reason, it will be logged as an error.