ahmed
ahmed

Reputation: 96

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 .

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 (pseudo code):

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

Upvotes: 0

Views: 49

Answers (1)

Theo
Theo

Reputation: 61068

= 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 at least 2 dots (.)"
}

Upvotes: 4

Related Questions