Skip to content

Code improvement in Discovery #17

@PChipVIA

Description

@PChipVIA

I would recommend changing the line as follows (code expandable for readability. I personally don't follow that best practice):
foreach($instance in $instanceUrls.Split(',') | %{$_.Trim()} | ? {$_ -notmatch '^\s*$'})

This solves multiple issues:

  • If the incoming $instanceUrls contains multiple entries and a space before or after the comma, then each url will be trimmed individually
  • Also ensures that only URLs containing data is present
  • We could actually force it to match service-now.com in the URL (or add it altogether, with more code)
  • As per VSCode PoSH best practices, if a string doesn't need variable expansion, then best to use single quotes
  • We could as well put the Where-Object before the For-Each, to filter out before trimming. Haven't checked what is the most efficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions