Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I have a small problem with the (if) command in PowerShell

First, I will show my project

$url = Read-Host 'URL'
if ( $url -notmatch '\.'){
    msg * "The title does not contain(.)"
}

Explanation of the code

The code should alert you that the site does not have a .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The problem is that the code alerts you if the link contains a . Once, I want him to alert me if he finds it. twice

Example:

$url = Read-Host 'URL'
if ( $url -notmatch '\.' = 2){
    msg * "The title does not contain(.)"
}

>Solution :

= is an assignment and not an operator for equality.

If you want the given url to have at least 2 dots in it, try

$url = Read-Host 'URL'
if ( [regex]::matches($Url, '\.').Count -lt 2 ){
    msg * "The url does not contain 2 dots (.)"
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading