Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Herdrich

Technical User
Dec 30, 2008
83
0
0
US
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
 
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.
 
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.
 
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.
 
Another way to write what you are going to try is SACCTX\d{3}.
 
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.
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top