# Elseif is unrecognized

**URL:** <https://forums.powershell.org/t/elseif-is-unrecognized/19154>\
**Category:** PowerShell Help\
**Created:** [April 21, 2022, 8:32pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154 "2022-04-21T20:32:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LwithaZ](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/lwithaz/32/2321_2.png) [@LwithaZ](https://forums.powershell.org/u/LwithaZ)\
**Post date:** [April 21, 2022, 8:32pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/1 "2022-04-21T20:32:47Z")

</div>

Hello!

I’m an absolute newbie (two weeks into learning PS) and I’ve hit a speedbump with the following code:

```auto
$path = 'C:\Test'

$evalPath = Test-Path $path

if ($evalPath -eq $true) {

    Write-Host "$path VERIFIED"

}

elseif ($evalPath -eq $false) {

    Write-Host "$path NOT VERIFIED"

}

```

I’m getting this error in the console when I run the above:

```auto
elseif: The term 'elseif' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

```

I’m unsure why I’m getting this error, as “if” is recognized. And I don’t think I have any open brackets (which seems to be a common cause to this issue in my research.) I’m using VS Code with PS v7.2.2

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 21, 2022, 8:58pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/2 "2022-04-21T20:58:19Z")

</div>

LwithaZ,  
Welcome to the forum. 👋🏽

> [@LwithaZ](#):
>
> I’m getting this error in the console when I run the above:

Simply move the `elseif` behind the closing curly brace of the if script block. 😉

But your code is a bit clunky anyway. Since the output of `Test-Path` is a `[boolean]` you can use it directly in the if statement. So it should look soemthing like this:

```auto
$path = 'C:\Test'
if (Test-Path -Path $path) {
    "$path VERIFIED"
}else {
    "$path NOT VERIFIED"
}

```

---

<div class="post-metadata">

**Author:** ![LwithaZ](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/lwithaz/32/2321_2.png) [@LwithaZ](https://forums.powershell.org/u/LwithaZ)\
**Post date:** [April 21, 2022, 9:07pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/3 "2022-04-21T21:07:45Z")

</div>

Like magic, thank you! And thanks for the cleanup of my script. I’m just getting my hands dirty with this stuff, so I appreciate knowing good habits early.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 21, 2022, 9:25pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/4 "2022-04-21T21:25:45Z")

</div>

> [@LwithaZ](#):
>
> so I appreciate knowing good habits early.

Then I have a reading recommendation for you

> **[GitHub - PoshCode/PowerShellPracticeAndStyle: The Unofficial PowerShell Best...](https://github.com/PoshCode/PowerShellPracticeAndStyle)**
>
> The Unofficial PowerShell Best Practices and Style Guide - GitHub - PoshCode/PowerShellPracticeAndStyle: The Unofficial PowerShell Best Practices and Style Guide

---

<div class="post-metadata">

**Author:** ![LwithaZ](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/lwithaz/32/2321_2.png) [@LwithaZ](https://forums.powershell.org/u/LwithaZ)\
**Post date:** [April 21, 2022, 9:50pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/5 "2022-04-21T21:50:52Z")

</div>

Oh hell yes! This is fantastic

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/elseif-is-unrecognized/19154/6 "2024-05-16T20:18:02Z")

</div>

Closed on May 16, 2024, 8:18pm UTC


