• Site for Newbie Windows Administrators
admincentric
  • Home
  • Active Directory
  • Hyper-V
  • PowerShell
  • Free Tools
  • Contact

PowerShell -eq Operator

Feb 09, 2024 Admin

In PowerShell, the `-eq` operator is used for comparison, specifically for testing equality between two values. It stands for "equals" and is commonly used in conditional statements and filtering operations. Here's a detailed explanation of how the `-eq` operator works:

The syntax for -eq operator is:

$value1 -eq $value2

Description

The `-eq` operator compares the values on either side of it to determine if they are equal. It returns a Boolean value, either `$true` if the values are equal or `$false` if they are not.

$number1 = 10
$number2 = 5
$result = $number1 -eq $number2
Write-Host $result

Example

In this example, `$result` will be `$false` because 10 is not equal to 5.


Additional Notes

The `-eq` operator is case-insensitive for string comparisons by default. To perform a case-sensitive comparison, you can use the `-ceq` operator.

"hello" -eq "Hello" # Returns $true
"hello" -ceq "Hello" # Returns $false (case-sensitive)

You can use the `-eq` operator in conditional statements such as `if` statements:

$a = 10
$b = 10
if ($a -eq $b) {
Write-Host "Values are equal"
} else {
Write-Host "Values are not equal"
}

The `-eq` operator can be used with various data types, including strings, numbers, and other objects.

Understanding the `-eq` operator is fundamental for writing PowerShell scripts that involve comparisons and conditional logic.

Home

Active Directory

Hyper-V

PowerShell

Free Tools

Contact

Trending News

How to enable Hyper-V in Windows? Coming Soon...

How to configure a Virtual Machine? Coming Soon...

Using PowerShell to manage a Virtual Machine Coming Soon...

How to install Active Directory on Windows Server 2016? Coming Soon...

How to create Active Directory Users? Coming Soon....

How to reset Active Directory User Passwords? Coming Soon...

How to unlock Active Directory User Accounts? Coming Soon...

Popular Resources

Popular resource 1 coming soon....coming soon

Popular resource 1 coming soon....coming soon

Popular resource 1 coming soon....coming soon

Popular resource 1 coming soon....coming soon

Table of Contents

Table of Contents

  • Description
  • Example
  • Additional Notes

Connect with us!

Company
  • About admincentric
  • Advertise with us
  • Contact
Pages
  • Webinars
  • Deals Store
  • Privacy Policy
Deals
  • Hacking
  • Development
  • Android
RSS Feeds Contact Us

© admincentric, 2023. All Rights Reserved.