OK, so this is a late start, but better to start late than never. And within 90 seconds of writing my first powershell script (the 90 seconds included the google and modifications) I had the collated results from 20 servers – nice!
So, where did I start: credit is due to this post for the 90 seconds turn around: Why This SQL Server DBA is Learning Powershell. So, rather than “Hello World”, my first script this time is as follows:
# Execute, on servers in $args[0], script in $args[1]
$dt = new-object System.Data.DataTable
foreach ($svr in get-content $args[0])
{
$con = "server=$svr;database=master;Integrated Security=sspi"
$cmd = get-content $args[1]
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con) $da.fill($dt) | out-null $svr }
# $dt | Format-Table -autosize
$output_csv = $args[1] + ".csv" $dt | export-csv -path $output_csv –noType
I’ll post further later, just wanted to get something out…which then means I will be motivated to blog/post further!