Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
948 views
in PowerShell by 24 25 33

I have the below programming code and I need to convert it to PowerShell script. What are the logical operators in PowerShell to write Less Than or Equal to value and Greater Than value?

If(var <= 10 && var > 0)
{
   printif "Hello World" 
}

1 Answer

2 like 0 dislike
by 159 198 381
selected by
 
Best answer

How to use Less Than or Equal To in PowerShell

In PowerShell, to can use the Logical operator Less than or Equal to, you have to use -le logical operator.

Example

$var = 5 
If($var -le 10 && $var -gt 0)
{
   Write-Host "Hello World" 
}

Logical Operators List in PowerShell

Below is the list of Logical Operators List in PowerShell:

1) Equal in PowerShell

-eq

Example

If($var -eq "debug")
{
   Write-Host "Hello World" 
}

2) Not Equal in PowerShell

-ne

Example

If($var -ne "debug")
{
   Write-Host "Hello World" 
}

3) Greater Than in PowerShell

-gt

Example

If($var -gt 10)
{
   Write-Host "Hello World" 
}

4) Greater Than or Equal in PowerShell

-ge

Example

If($var -ge 10)
{
   Write-Host "Hello World" 
}

5) Less Than in PowerShell

-lt

Example

If($var -lt "debug")
{
   Write-Host "Hello World" 
}
 

5) Less Than or Equal to in PowerShell

-le

Example

If($var -le 10)
{
   Write-Host "Hello World" 
}

6) Not in PowerShell

! OR -not

Example

If($var -not "debug")
{
   Write-Host "Hello World" 
}

7) OR in PowerShell

-or

8) And in PowerShell

-and

9) Like in PowerShell

 -like
If you don’t ask, the answer is always NO!
...