Creating multiple sheets in excel using powershell

fdrgiit

New Member
Hello Guys,

I saw this archived post here and hence, asking this question:
http://www.vistax64.com/powershell/174132-excel-powershell-open-workbook-multiple-sheets.html

I have written the following powershell script for getting the database status (offline or online):

Code:
cls
foreach ($svr in get-content "demo.txt")


{


  $con = "server=$svr;database=master;Integrated Security=sspi" 


  $cmd = "select state_desc as DB_STATUS,COUNT(name) as [TOTAL DB'S] from sys.databases group by state_desc"


  $da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)


  $dt = new-object System.Data.DataTable


  $da.fill($dt) |out-null


  $svr 
  $dt | Format-Table -autosize


}
The thing here is, I want to change this script in such a way that the output is exported to an excel file and as per the number of servers, new sheets should get created and the output get's stored accordingly, related to the server.
I'm not great at powershell, so kindly help me on this.
 

My Computer

Back
Top