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-CMDBUser: Check for existing user & improved logging #462

Closed
wants to merge 51 commits into from

Conversation

alexaxb
Copy link
Contributor

@alexaxb alexaxb commented Jun 2, 2023

Describe the change
Provide an explanation of the changes being made and why you want to make them
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.

AdhocAdam and others added 30 commits August 28, 2022 16:19
* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Closing curly bracket must not be preceded by a blank line

* codefactor, multiple line breaks and semicolon
* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Documentation header line must not be followed by a blank line. Opening/Closing curly bracket must not be followed/preceded by a blank line

* codefactor, blank lines

Closing curly bracket must not be preceded by a blank line

* codefactor, multiple line breaks and semicolon
* codefactor, blank lines

Closing curly bracket must not be preceded by a blank line.

* codefactor, multiple blank lines

The code must not contain multiple blank lines in a row
An opening curly bracket must not be followed by a blank line
* PSScriptAnalyzer, use singular nouns

To comply with best practices, functions should use singular nouns

* action trigger, remove linebreak

removing a line break so as to trigger github actions within a pull request
* icon, multiple keywords

adding icon for multiple keywords feature

* feature, multiple keywords

readme update for multiple keywords feature

* XAML, comma seperated keywords

modifies the regular expression on the text boxes for keywords so they can accept a single word or a series of words separated by a comma

* XAML, verbiage and UI resize

updating the XAML so the text boxes stretch as the Settings UI is resized. Also small verbiage changes in the header.

* feature, multiple keyword pwsh support

This change modifies the initial retrieval of keywords from the management pack so as handle a one or many keyword scenario PER keyword. The result of this is the current keyword variables are made regular expression friendly featuring a self-contained logical OR operation. e.g. \[(yes|approved|affirmative|roger)\] or in the case of a single word \[(yes)\]. In doing so, all subsequent actions taken against work items are preserved/reverse compatible while offering expanded functionality.

* XAML, from keyword

The "from" keyword is the only keyword whose exact substring position matters as it is used to identify the end of an email via the IndexOf() method. As such, it should not support multiple keyword instances.
If mail address contains a dash, the address won't be found in SCSM
The $userClass and $sysUserHasPrefRelClass variables are declared, but never used anywhere within the connector. Rather than delete them entirely, they have been commented out.
Upon some investigation of the function, it looks like PSScriptAnalyzer has an issue with the scope of $isMember. In order to fix this, an opportunity was presented that removes the initial $false declaration of $isMember, removes the foreach loop that checks each user of the group with the user coming into the function, and instead replaces it with a pipeline/where-object style operation. This also resulted in moving the logic for verifying if the group member is of type User.
While $alias is declared within Set-SCSMTemplate, it's only ever used in Update-SCSMPropertyCollection. As a result, alias has been introduced as a parameter to Update-SCSMPropertyCollection so as to properly receive the declared alias from Set-SCSMTemplate and resolve the error PSScriptAnalyzer is citing wherein $alias is declared but never used.
* usage, isVerifiedSig

isVerifiedSig is indirectly used because the operation to the right hand side of the = operator is actually performing the decryption and updating $decryptedBody. The result of isVerifiedSig is actually an array of digital signatures.

* logic and whitespace

removing whitespace caught by PSScriptAnalyzer on PR and adding logic to respect logging levels
* appname, using:

Addressing issue per PSScriptAnalyzer wherein a variable passed into Invoke-Command's scriptblock should make use of the using: scope modifier

* unhealthySCOMApp, using:

Addressing issue per PSScriptAnalyzer wherein a variable passed into Invoke-Command's scriptblock should make use of the using: scope modifier

* using: context

PSScriptAnalyzer is still throwing an issue about the using: context for the unhealthy app. Breaking out the name into its own variable.

* extra )

removing the closing ) from the previous commit
parentworkitem is never set for the default switch
since standardizing the message format via PSCustomObjects, this function should be using $message.From instead of $message.From.Address
$parentworkitem does not exist in the default workitemtype switch
…hocAdam#403)

* Update smletsExchangeConnector.ps1

If mail address contains a dash, the address won't be found in SCSM

* Wrong parameter data when calling Add-FileToSCSMObject

parentworkitem is never set for the default switch

* Revert "Wrong parameter data when calling Add-FileToSCSMObject"

This reverts commit 48c1252.
Description is missing the word "signed"
* get instance vs. textbox update

instead of retrieving the GUID of the chosen SCOM group from the Settings MP and then updating a text/label with the chosen name. The ConsoleContextHelper correctly updates and manages the Single Instance Picker control on the SCOMIntegrationForm.xaml

* remove label, format single instance picker

AdminSettingsWizardData now manages the SingleInstancePicker control. The label is no longer required.

* instance picker update

updating SCSM Announcement Group per previous commit on use of single instance picker and the SCOM Group picker

* remove DisplayName label

SingleInstancePicker now correctly updates per AdminSettingsWizardData

* single instance picker

updating announcement group logic for single instance picker
* contributor list

updating the list of contributors per pull requests AdhocAdam#403 and AdhocAdam#410

* contributor list

updating the list of contributors seen in the Settings UI per pull requests AdhocAdam#403 and AdhocAdam#410
* logging icon and line breaks

Adding line breaks for the logging options and the Event Log icon

* template icon

instead of the smlets exchange connector icon it should be the SCSM Template icon

* icons, event log and template

adding icons for updated Logging and Template forms

* build icons

include the icons in the build so they are included into the Settings UI dll so they can be referenced in the XAML forms
it seems in certain configurations, SMLets isn't loaded soon enough in the connector's overall execution. As a result this prevents the script from successfully running.
Previously if there were no messages to processes, the event order would be (at a minimum) 0 = connected to exchange and then 5 = filtering mailbox. There was no indication that there were 0/no messages to process and/or that 5 was the "last" event one would see for a run of the connector. As such, the logging could be misinterpreted as the connector not successfully completing a run. This change removes that uncertainty as the event is now logged regardless of the number of messages to process as well as introducing event 6 which shows the total runtime of the connector for a given number of messages. Now the minimum logging order is 0, 5, 2, 6 which is more representative of a start, connect, process and finish of the connector.
* Update smletsExchangeConnector.ps1

If mail address contains a dash, the address won't be found in SCSM

* Wrong parameter data when calling Add-FileToSCSMObject

parentworkitem is never set for the default switch

* Revert "Wrong parameter data when calling Add-FileToSCSMObject"

This reverts commit 48c1252.

* Added logging for OAuth

* event numbering

updating event log numbering

Co-authored-by: Adam <adhocadam@protonmail.com>
alexaxb and others added 17 commits November 22, 2022 07:46
When an Incident is created, it uses a - instead of a : to build the DisplayName property
closer inspection of creating Work Items in the console show there is a difference in spacing for the DisplayName on Problem and Change Requests
* Update smletsExchangeConnector.ps1

If mail address contains a dash, the address won't be found in SCSM

* Wrong parameter data when calling Add-FileToSCSMObject

parentworkitem is never set for the default switch

* Revert "Wrong parameter data when calling Add-FileToSCSMObject"

This reverts commit 48c1252.

* Added logging for OAuth

* Add displayname to new workitems as in the console

* different separator character

When an Incident is created, it uses a - instead of a : to build the DisplayName property

* character spacing

closer inspection of creating Work Items in the console show there is a difference in spacing for the DisplayName on Problem and Change Requests

Co-authored-by: Adam <adhocadam@protonmail.com>
Added -Alias $alias to the recursive Update-SCSMPropertyCollection call
Whenever the update-workitem is called with a message, where the length of the body is greater than 4000, the substring(0,4000) function is called, but the result is not written back to the commentToAdd variable - so the full message is further processed, and the action log is not added to the workitem.
…ge Regex (AdhocAdam#453)

* Update smletsExchangeConnector.ps1

* Update smletsExchangeConnector.ps1

* update reply regex

adding square brackets to two of the reply regexes to be consistent with the rest of the patterns

---------

Co-authored-by: Adam <adhocadam@protonmail.com>
$true/$false values are incorrectly tied to the logging level used by the connector. This moves them out of that logic and ensures $ceScripts always has a value
Per PSScriptAnalyzer, this specific regex reply pattern is throwing a warning. It's possible this can be overcome, but short of further research/holding the release it's going to be removed for now. https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/usebomforunicodeencodedfile?view=ps-modules
* powershell contributors

updating powershell contributor list per pull requests/commits

* update contributors on AboutForm.xaml

updating the contributor list per pull requests/commits
updating inline version notes with relevant issues/pull requests
@AdhocAdam AdhocAdam changed the base branch from dev to dev-5.x June 6, 2023 15:10
@AdhocAdam
Copy link
Owner

Two things:

  • I tried updating your branch/fork with a new branch I created called "dev-5.x" that is essentially the current production deployed connector for 5.0.3. While it looks like this still includes a lot of commits since your initial fork/sync, the one thing I noticed is you have a $startTime variable. I assume this is carry over from some commit (I don't know where) and wasn't intentional on your part?
  • I've encountered what you're proposing in this pull request I want to say, less than 5 times in the history of the connector. Which is to say, it's never happened enough or with any pattern that I could identify how the connector creates a User gets without a Notification Channel and/or fails to create the related Notification Channel. In any case, I don't think I'm opposed to what you're proposing. I've just been spending time thinking about if there is some danger in doing this I'm/we're not possibly seeing.

@alexaxb
Copy link
Contributor Author

alexaxb commented Jun 8, 2023

Hmm.. $startTime was not intentional, so I've removed it now. Probably a leftover from dev testing.

A plan B if we don't won't to update the user automatically, could be that we simply create a tailored error message for this scenario when it happens, so it's clear in the log why the connector stops importing new mail when it occurs.

@AdhocAdam AdhocAdam self-assigned this Jun 22, 2023
@AdhocAdam AdhocAdam added this to the 5.x.x milestone Jun 22, 2023
@AdhocAdam
Copy link
Owner

Cherry picked the commit to maintain a cleaner history while still ensuring you're given proper credit. Closing this PR and moving over to #470

@AdhocAdam AdhocAdam closed this Aug 10, 2023
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

3 participants