list tables using wild card sql powershell

Answered list tables using wild card sql powershell

  • Thursday, May 03, 2012 11:14 PM
     
     

    I have a script below that should list database tables like "t_asdasd312" and "a_9ukjd" but when I execute it somehow returns all other tables.

    Can some please tell me whats wrong?

    cd SQLSERVER:\SQL\dbname\DEFAULT\Databases\databasename\tables
    Get-ChildItem | where{$_.name  -match "[ta]_\w+"}

All Replies

  • Thursday, May 03, 2012 11:25 PM
     
     Answered

    "^t|^a\w+"

    You need to specify from the beginning of teh string and not use cahracter classes.  Just say t|a which means "t" or "a".  Add the hat and you are set to go.


    ¯\_(ツ)_/¯

    • Marked As Answer by rocky_don Friday, May 04, 2012 12:04 AM
    •  
  • Friday, May 04, 2012 12:07 AM
     
     
    thank you!!! jrv I tweaked your answer slightly "^t_|^a_\w"  since the tables I am looking for are t_XXX... or a_xxxx...