SHARE
TWEET

Database loop example

mike_fal Mar 17th, 2015 226 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top