locked
get-aduser with ! regex RRS feed

  • Question

  • I needed to select all users where the samaccount name begins with 3 letters and then has 4 numbers like this abc1234
    and also to select all users where the samaccountname begins with 4 letters  and then as 3 numbers like this abcd123

    This works great

    $reg = "[a-z]{3}\d{4}"
    $reg2 = "[a-z]{4}\d{3}"

    get-aduser -filter * -properties * |? {(($_.samaccountname -match $reg -or $_.samaccountname -reg2)

    Now I need to select users where the samaccount doesnt match $reg or $reg2

    Ive tried "/^(![a-z]{3}\d{4})" and a bunch of other iterations but, havent found the correct combination yet.

    Any ideas?

    Thanks - Steve


    --------- SteveP

    Wednesday, April 24, 2019 1:52 PM

Answers

  • I solved it myself.

    I was trying to figure out the ! version of regex.

    I just changed $_.samaccountname -match to -notmatch

    works great.

    Steve


    --------- SteveP

    • Marked as answer by speterson400 Wednesday, April 24, 2019 1:55 PM
    Wednesday, April 24, 2019 1:55 PM