PowerShell Greater Than or Equal [With Examples]

If you’ve ever needed to compare numbers, dates, or even objects in PowerShell, you’ve probably wondered how to check if one value is greater than or equal to another. In this tutorial, I’ll walk you through the “greater than or equal” operator in PowerShell using examples.

PowerShell Comparison Operators

Comparing values is at the heart of scripting logic. PowerShell comes loaded with several comparison operators to help us write powerful and concise scripts. The two most relevant here are:

OperatorDescription
-geGreater than or equal to
-gtGreater than

We often use -ge for conditional checks, loops, filtering data, and validating user input.

Check out PowerShell Find All Files With Extension

Use -ge for Number Comparison

The -ge operator is straightforward for integers and decimals. I always recommend this approach for any numeric validations, such as checking disk space, memory usage, or user quotas.

Before the code: I use -ge to determine if a number meets or exceeds a threshold.

Here is the code example:

$cpuUsage = 85
if ($cpuUsage -ge 80) {
    Write-Output "Warning: CPU usage is high."
}

After the code: This script checks if CPU usage is 80 or greater. When true, it triggers a warning.

I executed the above PowerShell script, and you can see the exact output in the screenshot below:

PowerShell Greater Than or Equal

Check out Find Files Older Than a Specific Date using PowerShell

Compare Strings with -ge

PowerShell compares strings lexicographically (alphabetically). The comparison is case-insensitive by default, which is handy for most real-world tasks.

Before the code: Compare user roles or states effortlessly, knowing PowerShell handles them as text.

Below is the code example:

$userRole = "Manager"
if ($userRole -ge "admin") {
    Write-Output "Elevated permissions granted."
}   else {
    Write-Output "Standard permissions granted."
}

After the code: This example grants permissions to anyone whose role is alphabetically after or equal to “admin”.

You can see the exact output in the screenshot below:

PowerShell Greater Than or Equal Operator

Read PowerShell Select-String Examples

Compare Dates and Times With -ge Comparison Operator

When working with logs or scheduling scripts, I frequently compare dates. PowerShell treats dates as objects, so the operator compares actual datetime values.

Before the code: Determine if a system event occurred after a certain date using simple syntax.

Code Example:

$eventDate = Get-Date "2025-09-10"
$thresholdDate = Get-Date "2025-01-01"
if ($eventDate -ge $thresholdDate) {
    Write-Output "Event happened this year."
}

After the code: Here, PowerShell verifies if $eventDate is on or after $thresholdDate. This makes log reviews and auditing scripts much simpler.

Filter Data with Where-Object and -ge Operator

With large lists or objects, I filter results based on criteria using Where-Object in combination with -ge.

Before the code: Streamline reports or searches by returning only results meeting your conditions.

Code Example:

$users = @(
    @{Name="Alice";Age=29},
    @{Name="Bob";Age=34},
    @{Name="Charlie";Age=22}
)
$adults = $users | Where-Object { $_.Age -ge 30 }
$adults | ForEach-Object { Write-Output "$($_.Name) is an adult." }

After the code: This finds all users aged 30 or above. It’s highly efficient for user management and reporting tools.

Here is the exact output in the screenshot below:

PowerShell Greater Than or Equal Operator Example

Use -ge with Logical Operators

When scripts require robust logic, I often combine -ge with -and, -or, or other operators.

Before the code: Check multiple resource thresholds to trigger actions in automation workflows.

Code Example:

$diskSpace = 75
$memory = 32
if ($diskSpace -ge 70 -and $memory -ge 30) {
    Write-Output "Resources are sufficient for deployment."
}

After the code: Only when both disk space and memory are above set limits does the script allow deployment—critical for infrastructure automation.

Check out Concatenate String in Write-Host In PowerShell

Best Practices of Using -ge Operator

  • Always validate data types before comparing (e.g., numbers vs strings).
  • Remember, string comparisons are alphabetical, not numerical.
  • Use [int][datetime] type casting where appropriate.
  • For robust scripts, handle possible null or empty values.
ScenarioRecommendation
Numeric comparisonsUse directly with -ge
String comparisonsBe aware of alphabetical order
Mixed types (e.g., string vs int)Cast to appropriate type
Collections filteringUse Where-Object with -ge

Conclusion

As a developer, you should know how to use the greater than or equal operator in PowerShell. Here, we saw how to use this operator with numbers, strings, and dates in PowerShell. Do let me know in the comments if you have any questions or suggestions.

You may also like the following tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App