Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use if else in my powershell script. in the if side, it works, but in the else side, It cannot return "Not Found" . It does not show any error.


What I have tried:

if ($match.Groups.Count) {
    while ($match.Success) {
        Write-Host ("Match found: {0}" -f $match.Value)
        $match = $match.NextMatch()
    }
}
else {

    Write-Host "Not Found"
}
Posted
Updated 10-Mar-19 18:17pm
Comments
Bryian Tan 10-Mar-19 23:15pm    
Have you try
if ($match.Groups.Count >0 )
?

1 solution

if ($matching.Success) {
    while ($matching.Success) {
        "Match found: {0}" -f $matching.Value
        $matching = $matching.NextMatch()
    }
}
else {

    "Not Found"
exit
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900