EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell not like
 

PowerShell not like

Priya Pedamkar
Article byPriya Pedamkar

Updated March 3, 2023

PowerShell not like

 

 

Introduction to PowerShell not like

The following article provides an outline for PowerShell not like. Comparison operators let the users indicate conditions for comparing values and finding values that satisfies the mentioned condition. To utilize a comparison operator, indicate the values that you just need to compare along with an operator that isolates these values. The not like operator is a type of matching comparison operator. This along with like, match and not match operators are part of the matching comparison operator type. The not like operator returns true if the string doesn’t match the specified condition. Here we will see about not like operator along with other matching operators.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax of not like operator:

Given below is the syntax of not like operator:

<string[]> -notlike <wildcard-expression>

Example:

Code:

"vigneshkrishnakumar" -notlike "*mar"
"vigneshkrishnakumar" -notlike "*sethu"

Output:

PowerShell not like 1

Working of not like Operator

The like operator uses wild card expression for comparison. For example, let us consider a sentence “how old are you?” If we execute the cmdlet “how old are you” -like “*you”, the cmdlet will return true however if the cmdlet is modified to “how old are you” -like “you”, the cmdlet will return false. It is due to the asterisk symbol before you. The asterisk symbol stands for wild card expressions.

If the wildcard is present in the beginning of the comparison text, it means anything can be before the searched expression whereas if the asterisk is present at the end, it means the searched expression should have something followed by it. In the above example if the asterisk is placed after the text it will return false. The not like operator is the exact opposite of the like operator. It will return true when there the condition is false and false when there is a match.

Example:

Code:

Write-Host " wild card before the comparison text" -ForegroundColor Green
“my name is Vignesh krishnakumar” -like “*is”
Write-Host "no wild card involved" -ForegroundColor Green
“my name is Vignesh krishnakumar” -like “is”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“my name is Vignesh krishnakumar” -like “is*”
Write-Host " wild card before the comparison text" -ForegroundColor Green
“my name is Vignesh krishnakumar” -notlike “*is”
Write-Host "no wild card involved" -ForegroundColor Green
“my name is Vignesh krishnakumar” -notlike “is”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“my name is Vignesh krishnakumar” -notlike “is*”

Output:

PowerShell not like 2

Comparing like and not like with match and not match

Another type of comparison operator is match / non match operator. Although comparative to Like, it’s much more PowerShell (however a small more complicated). The match or non match operators administrator employments customary expressions (regex). This is often a gigantic advantage and gives Coordinate an unequivocal leg up on Like. In any case, in case you’ve never utilized customary expressions some time recently, plan yourself. Let’s go with our past illustration string once more.

Syntax for match and not match operator:

<string[]> -match <regular-expression>

<string[]> -notmatch <regular-expression>

Example #1:

Code:

"sun", "mon","tue","wed","thu","fri","sat" -match "su"
"viki", "vignesh","vikiii","vikii","nandhini","vyapini","sethu" -notmatch "viki"

Output:

PowerShell not like 3

Example #2:

Code:

Write-Host " wild card before the comparison text" -ForegroundColor Green
“my name is Vignesh krishnakumar” -match “*is”
Write-Host "no wild card involved" -ForegroundColor Green
“my name is Vignesh krishnakumar” -match “is”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“my name is Vignesh krishnakumar” -match “is*”
Write-Host " wild card before the comparison text" -ForegroundColor Green
“my name is Vignesh krishnakumar” -notmatch “*is”
Write-Host "no wild card involved" -ForegroundColor Green
“my name is Vignesh krishnakumar” -notmatch “is”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“my name is Vignesh krishnakumar” -notmatch “is*”

Output:

wild card before comparison text

As you can see from the above output, the match operator doesn’t work with wild card expressions.

Example #3:

Code:

$start=(Get-Date).Millisecond
Write-Host " wild card before the comparison text" -ForegroundColor Green
“corona originated in china but now it is cured there” -like “*there”
Write-Host "no wild card involved" -ForegroundColor Green
“corona originated in china but now it is cured there” -like “there”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“corona originated in china but now it is cured there” -like “there*”
Write-Host "wild card before the comparison text"-ForegroundColor Green
“corona originated in china but now it is cured there” -notlike “*there”
Write-Host "no wild card involved" -ForegroundColor Green
“corona originated in china but now it is cured there” -notlike “there”
Write-Host "wild card after the comparison text" -ForegroundColor Green
“corona originated in china but now it is cured there” -notlike “there*”
$end=(Get-Date).Millisec
Write-Host "Total time in milli seconds for like and not like: $($start-$end)" -ForegroundColor Yellow
$start1=(Get-Date).Millisecond
Write-Host " wild card before the comparison text" -ForegroundColor Green
“corona originated in china but now it is cured there” -match “there”
Write-Host "no wild card involved" -ForegroundColor Green
“corona originated in china but now it is cured there” -match “now”
Write-Host "wild card after the comparison text"-ForegroundColor Green
“corona originated in china but now it is cured there” -match “america”
Write-Host "wild card before the comparison text"-ForegroundColor Green
“corona originated in china but now it is cured there” -notmatch “america”
Write-Host "no wild card involved" -ForegroundColor Green
“corona originated in china but now it is cured there” -notmatch “sweden”
Write-Host "wild card after the comparison text" -ForegroundColor Green
“corona originated in china but now it is cured there” -notmatch "china”
$end1=(Get-Date).Millisec
Write-Host "Total time in milli seconds for match and not match: $($start1-$end1)" -ForegroundColor Yellow

Output:

wild card before the comparison text

As you can see from the above output, like and not like took lesser time to execute.

Conclusion – PowerShell not like

Thus, in this article we saw about the not like operator in detail. Here we saw the syntax, the usage and its advantage with appropriate examples. Here we also saw the match and not match operators and its similarities and differences with not like operator.

Recommended Articles

This is a guide to PowerShell not like. Here we discuss working of not like operator and comparing like and not like with match and not match. You may also have a look at the following articles to learn more –

  1. PowerShell Continue
  2. Windows PowerShell ISE
  3. PowerShell Rename Folder
  4. PowerShell Get-Service

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW