PowerShell Verify if Paramater Substring is Between A and Z

I am trying to build a PowerShell script that checks the 5th character in a paramter and checks to see if it is letter in the alphabet between A and Z. However, I am not sure how to check for that.

This is what I have so far... but it doesn't work...
# Check for Alpha
 
$nameone = P1234W1054 
 
IF ($nameone.Substring(5,1) -eq "[a-z]"
{
  "Is in the alphabet"
}
else
{
  "Not in the Alphabet"
}

Open in new window

LVL 3
computerstreberAsked:
Who is Participating?
 
LearnctxConnect With a Mentor EngineerCommented:
Try
# Check for Alpha
 
$nameone = "P1234W1054"
 
if ($nameone.Substring(5,1) -match "[a-z]"
{
  "Is in the alphabet"
}
else
{
  "Not in the Alphabet"
}

Open in new window

0
 
LearnctxEngineerCommented:
Also there's a syntax error on the end of line 5, add a closing ).
0
 
computerstreberAuthor Commented:
Worked Perfectly!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.