0

How am I able to append some HTML tags (<td></td>) to an existing property?

I've been stuck on this one for a little while now with no luck...

$teamConfig = @(
    [pscustomobject]@{
        TeamName  = 'Team1'
        TeamEmail = '[email protected]'
    }
    [pscustomobject]@{
        TeamName  = 'Team2'
        TeamEmail = '[email protected]'
    }
)

$query = "select * from INCAutomation"

$results = Invoke-Sqlcmd -query $query -ServerInstance 'localhost' -Database 'AyushTest'

$teamTickets = foreach($team in $teamConfig){
  # Filter tickets based on team name
  $ticketIds = $results |Where-Object TeamName -eq $team.TeamName |Select -ExpandProperty TicketID

  # Output a single object per team, with all ticket IDs attached
  $team |Select TeamName,TeamEmail,@{Name='TicketID';Expression={$ticketIds}}
}

$teamTickets

Output:

TeamName TeamEmail        TicketID
-------- ---------        --------
Team1    [email protected] {INC0001, INC0002, INC0003, INC0004}
Team2    [email protected] {INC0005, INC0006, INC0007}

Desired output:

TeamName TeamEmail        TicketID
-------- ---------        --------
Team1    [email protected] {<td>INC0001</td>, <td>INC0002</td>, <td>INC0003</td>, <td>INC0004</td>}
Team2    [email protected] {<td>INC0005</td>, <td>INC0006</td>, <td>INC0007</td>}

Thanks in advance!

1 Answer 1

1

I think you should run them through a loop and modify each string to add the desired text. You can do that and add the modified strings to a new object, which you can use to replace the original $ticketIds variable as the Expression in your output.

Here's an example of your code, modified:

$teamConfig = @(
    [pscustomobject]@{
        TeamName  = 'Team1'
        TeamEmail = '[email protected]'
    }
    [pscustomobject]@{
        TeamName  = 'Team2'
        TeamEmail = '[email protected]'
    }
)

$query = "select * from INCAutomation"

$results = Invoke-Sqlcmd -query $query -ServerInstance 'localhost' -Database 'AyushTest'

$teamTickets = foreach($team in $teamConfig){
    # Filter tickets based on team name
    $ticketIds = $results |Where-Object TeamName -eq $team.TeamName |Select -ExpandProperty TicketID

    # Create an empty array
    $ticketIdArray = @()
    foreach ($id in $ticketIds) {
        # Modify the string to include the desired output
        $thisId = '<td>' + "$id" + '</td>'
        # Add the modified string to the empty array
        $ticketIdArray += $thisId
    }

    # Output a single object per team, with all ticket IDs attached
    $team |Select TeamName,TeamEmail,@{Name='TicketID';Expression={$ticketIdArray}}
}

$teamTickets
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.