PowerShell i loop kroz spisak servera
I evo PS skriptića koji vrti petlju sa dva člana :
param(
[string]$pauza = “———-”
)
$spisakservera = @(“mojserver1.mojdomen”,”mojserver2.mojdomen”)
for ($i=0; $i -lt 2; $i++) {
$pauza
$spisakservera[$i]
$pauza
Invoke-SQLCmd -query “select name, size*8/1024 AS KB from sys.master_files where name != ‘master’ AND name != ‘mastlog’ AND name != ‘tempdev’ AND name != ‘templog’ AND name != ‘modeldev’ AND name != ‘modellog’ AND name != ‘MSDBData’ AND name != ‘MSDBLog’;” -ServerInstance $spisakservera[$i]
}
Paziti samo, neke verzije SQL servera NEMAJU sys.master_files, ili u njemu nemaju imena svih svojih baza.
SQL 2012 koristiti sys.master_files
SQL 2008 koristiti sys.databases (tu istina nema podataka o veličinama baza, samo o imenima)
SQL 2008+2000 koristiti sysdatabases