$q contains a string array of each Git stdout line. To use -notcontains , you will need to combine the full string of the element in the array, for example:
$q -notcontains "nothing to commit, working directory clean"
If you want to check for partial line matches, try the -match . (Note: It uses regular expressions and returns a string that matches.)
$q -match "nothing to commit"
-match will work if the left operand is an array. So you can use this logic:
if (-not ($q -match "nothing to commit")) { "there was something to commit.." }
Another option is to use the -like / -notlike . They accept wildcards and do not use regular expressions. An array element that matches (or doesn't match) will be returned. So you can also use this logic:
if (-not ($q -like "nothing to commit*")) { "there was something to commit.." }
source share