0

I am trying to ascertain between two 3rd party support services which of our tickets are showing as closed on both portals. I have a CSV export of the tickets and both have the relevant fields.

Thus far I have this:

$EXTrange = Import-Csv -Path '/Range.csv'
$INTrange = Import-Csv -Path '/export (14).csv'

$ClosedInternal = $INTrange |
                  Where-Object status -eq "Closed"
$ICTickets = $EXTrange |
             Where-Object "Customer Ticket Reference" -eq $ClosedInternal

foreach ($thing in $ClosedInternal) {
    Write-Host $ICTickets."Ticket ID"
}

Customer Ticket Reference and ID fields will match up as they're our ticket numbers.

I just need to compare these two lists, match up the external and internal reference fields, check if it is closed in status and if it is then tell me the external company ticket ref held in $EXTrange."Ticket ID".

I feel like im close but can't figure out how to return the ticket ID for each matching ticket that is closed.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Samuel A
  • 13
  • 2
  • Using this [`Join-Object`](https://www.powershellgallery.com/packages/Join) cmdlet with the syntax `$ClosedInternal | Join $ICTickets -on 'Ticket ID' -eq 'Customer Ticket Reference' -Discern INT,EXT ` should give you a complete overview of all the properties at both sides (See also: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026)) – iRon Nov 13 '19 at 13:28

1 Answers1

0

$ClosedInternal presumably is an array, and also contains objects, not just the value(s) of the property you want to check. Comparing that to a simple value will always yield the result "not equal". You need the -contains operator (alternatively the -in operator if you're running at least PowerShell v3) if you want to check for the presence of a particular value in a list of values, and you need to expand the relevant property of a list of objects to get that list of values to compare against.

Change this:

$ClosedInternal = $INTrange |
                  Where-Object status -eq "Closed"
$ICTickets = $EXTrange |
             Where-Object "Customer Ticket Reference" -eq $ClosedInternal

into this:

$ClosedInternal = $INTrange |
                  Where-Object status -eq "Closed" |
                  Select-Object -Expand 'Ticket ID'
$ICTickets = $EXTrange |
             Where-Object $ClosedInternal -contains "Customer Ticket Reference"

and the code should do what you want. Replace 'Ticket ID with the correct name if the ID property of your internal tickets is named differently.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • This almost works, and indeed i tweaked it and made it work and promptly broke it again :( the subsequent foreach just lists empty data into the ISE console. $closedinternal does return the in-house ticket references but doesnt seem to expand out the $extrange."ticket ID" field – Samuel A Nov 13 '19 at 14:52
  • @SamuelA If you think that comment of yours provides any information that would allow me to even guess what the new problem might be: it doesn't. Either update your question with a more detailed description of your updated code and problem, or post a followup question. – Ansgar Wiechers Nov 13 '19 at 14:55