Get Exclusive value

You’ve not provided a good example of your data so I’ve just used an array and simplified your code.

If you don’t use the Escape() method, you can append $ to show that that’s the end of the string that should be matched:

$lookupTable = @(
    'hundred-gigabit-ethernet-1/1/1',
    'hundred-gigabit-ethernet-1/1/10',
    'hundred-gigabit-ethernet-1/1/11',
    'hundred-gigabit-ethernet-1/1/12',
    'hundred-gigabit-ethernet-1/1/13',
    'hundred-gigabit-ethernet-1/1/14'
)

$port = 'hundred-gigabit-ethernet-1/1/1'

$lookupTable | Where-Object { $_ -match "$($port)$" }

The sub-expression $($port) isn’t strictly necessary - { $_ -match "$port$" } would work - but I think using the sub-expression makes it easier to read.

1 Like