Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell: If string startswith a or b

$
0
0

Hey,

I'm trying to see if a string startswith a or b or c or d or f or g.. yeah.. basically a-g. Is that possible using this method?


$All = Get-ADGroupMember Groupname | select samaccountname
    Foreach ($User in $All)
        {
        If ($user.name.startswith("A")) 
            {"This works"
            }
        }

######### This is what I want..: (but it doesnt work)
$All = Get-ADGroupMember Groupname | select samaccountname
    
    Foreach ($User in $All)
        {
        If ($user.name.startswith("A-G")) 
            {"This works"
            }
        }



# This works, but it should not be necessary

If (($user.name.startswith("a")) -or ($user.name.startswith("b"))) {"This works"}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>