We help IT Professionals succeed at work.

PowerShell Verify if Paramater Substring is Between A and Z

computerstreber
on
Medium Priority
4,107 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Engineer
CERTIFIED EXPERT
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
LearnctxEngineer
CERTIFIED EXPERT

Commented:
Also there's a syntax error on the end of line 5, add a closing ).

Author

Commented:
Worked Perfectly!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.