I found that
$(Invoke-Expression hostname) -eq 'mycomputername'
Whether it is matched or not, the exitcode must be 0 this behavior is different from linux ,i.e, if not match error code exit 1
Is there any short command in PowerShell that can return error exit code if doesn't match the string?