$start = get-date
write-host “Start: ” $start
[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | out-null
## Specify path of output file
$FilePath = “D:\Version\”
$OutFile = Join-Path -path $FilePath -childPath (“SQLVersions_” + (get-date).toString(‘yyyyMMdd_hhmmtt’) + “.log”)
## Output file name will be like “X:\Monitoring_Automation\ SQLVersions_20130906_1248AM.log”
# Below is loop to generate version of each server
@(foreach ($svr in get-content “D:\Version\Monitoring_servers.txt”)
{
$s = New-Object “Microsoft.SqlServer.Management.Smo.Server” $svr
$s | select Name, Version
}) | export-csv -noType $OutFile
$end = get-date
write-host “End: ” $end
Leave a Reply