INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Filter by server name Get-ADComputer -Filter {Name -Like $filter}

Filter by server name Get-ADComputer -Filter {Name -Like $filter}

Filter by server name Get-ADComputer -Filter {Name -Like $filter}

(OP)
Hello all,

Im trying to sort by servers named SACCTX001 - SACCTX999 but everything I have tried seems to not work. What I have currently brings up some extra servers that I do not need I have tried SACCTX[0-9], SACCTX### and SACCTX/n. Does anyone know what I should be using?

CODE -->

$filter = "SACCTX*" 
$ADDomain = "OU=Citrix,OU=Servers,OU=DDC,dc=deltads,dc=ent"
$servers = Get-ADComputer -SearchBase $ADDomain -Filter {Name -Like $filter} | Sort-Object Name | Select-Object -ExpandProperty Name 


Thanks,
Glenn

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

What extra servers names are you getting that you don't want?


Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

What about

SACCTX[0-9][0-9][0-9]


Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

(OP)
I will try the SACCTX[0-9][0-9][0-9] in the morning although I believe I have tried that already. I am trying to get things that are like SACCTX123 and NOT like SACCTXABC.

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

Another way to write what you are going to try is SACCTX\d{3}.

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

(OP)
I tried SACCTX[0-9][0-9][0-9] and SACCTX\d{3} but it pulled no servers in my full code. Also found out today that I can run the commands I needed on all of the SACCTX* servers so I will just leave it as is. Thanks for the recommendations. I will still toy around with it to see if I can find a solution. My work around was using

CODE -->

$server = $server | findstr /i SACCTX[0-9] | Sort 

after the get-adcomputers was ran. I don't think you can use the \d and [0-9] for the -Like variables. I haven't been able to find anything on it so far.

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

I was playing around see if this helps, hope i'm on the right track

CODE -->

$Variable = "^SACCTX[0-9]"

write-output "$($Variable)"
Get-ADComputer -properties Name, OperatingSystem -Filter *| ?{$_.name -match "$($Variable)"} | Sort-Object Name | Select-Object -ExpandProperty Name 

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP

RE: Filter by server name Get-ADComputer -Filter {Name -Like $filter}

(OP)
Nice that works I knew it had something to do with -match because I only found references to [0-9] about -match and not like.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close