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

Check for existing user in New-CMDBUser #470

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft

Conversation

AdhocAdam
Copy link
Owner

@AdhocAdam AdhocAdam commented Aug 9, 2023

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.

BetaLyte and others added 4 commits July 15, 2023 16:05
Extends regex pattern support on MultipleMailboxes.xaml
…467)

* Update smletsExchangeConnector.ps1

* Update smletsExchangeConnector.ps1

* Remove-SCSMRelationshipObject one liner

After testing it does not appear there is a scenario wherein the try/catch will engage.

---------

Co-authored-by: Adam <adhocadam@protonmail.com>
Introduce logging events for functions that are responsible for obtaining suggestion URLs (KB/RO) from one's Cireson portal
in the event the Suggestions are enabled and the email subject/body contain regex patterns, this will ensure they are escaped correctly
@AdhocAdam
Copy link
Owner Author

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.

  1. Get-SCSMUserByEmailAddress engages. user@lab.lcl cannot be matched to a related Domain User object
  2. New-CMDBUser engages. The user is found, but they don't have a related Notification Channel object. The Notification Channel is created and the email (target) address is set
  3. Connector carries on and ultimately finishes up

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.

@AdhocAdam AdhocAdam removed this from the 5.0.4 milestone Sep 7, 2023
@AdhocAdam AdhocAdam changed the base branch from dev to dev-Temp September 10, 2023 19:05
@AdhocAdam AdhocAdam changed the base branch from dev-Temp to dev September 10, 2023 19:05
@alexaxb
Copy link
Contributor

alexaxb commented Sep 11, 2023

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.

@pwahlmueller
Copy link

We experience the same issue.
We can reproduce it:

  1. Send E-Mail with new User to Service Manager
  2. SMLets Exchange Connector creates the user without the notification
  3. Sending an E-Mail again results in the error.

@AdhocAdam
Copy link
Owner Author

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.

@pwahlmueller
Copy link

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.

@pwahlmueller
Copy link

pwahlmueller commented Oct 13, 2023

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

@pwahlmueller
Copy link

So think I'd to add a new PR for my changes, see #477

@pwahlmueller
Copy link

If you want to do

  • create user, if it does not exist
  • add user details, if it does exist

It is recommended to use the verb Set for the function instead of new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants