Answer the question
In order to leave comments, you need to log in
How to throw an exception in PowerShell if the output of the previous command does not match the regular expression?
For example, I want to make sure that the PHP version is exactly what I need and continue executing the script, otherwise throw an exception. I check like this:
Invoke-Expression "php -v" | Select-String -Pattern "PHP 7.4"
Further, as I understand it, there should be another pipe and a command that, if an empty string is received, will throw an exception, but I can’t find anything like it. Tell me how to do it.
Answer the question
In order to leave comments, you need to log in
Invoke Expression "php -v" | Where-Object {$_ -like "PHP 7.4"}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question