Advertisement
mike_fal

Database loop example

Mar 17th, 2015
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. Import-Module sqlps -DisableNameChecking
  2.  
  3. $dbs = Invoke-SqlCmd -ServerInstance 'localhost' -Query 'select name from sys.databases where database_id > 4'
  4.  
  5. foreach($db in $dbs){
  6. Invoke-Sqlcmd -ServerInstance 'localhost' -Database $db.name -Query 'select count(1) from sys.objects'
  7. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement