Search code examples
powershellpowercli

find variable on an other one with powershell using substring


I want to check if the content of variable A is present in the content variable B with powershell:

variable A = PROD 
variable B = xxxxxPRODxxxx

Solution

  • you can use -match to compare using regex

    $keyword = 'PROD'
    $string = 'xxxxxPRODxxxxx'
    if($string -match $keyword){write-host 'matched'}