From fa64299760b66dd3a05b3bbc4588a09ac5696cdc Mon Sep 17 00:00:00 2001 From: Aaron Nelson Date: Thu, 4 Oct 2018 14:29:33 -0400 Subject: [PATCH] Added Example for SQL Server Added an example for running a query from a SQL Server database using the Invoke-Sqlcmd cmdlet, and then exporting the results to Excel. --- Export-Excel.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index cea61c2..ca86ed2 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -381,6 +381,16 @@ 0..360 | ForEach-Object {[pscustomobject][ordered]@{X=$_; Sinx="=Sin(Radians(x)) "} } | Export-Excel -now -LineChart -AutoNameRange Creates a line chart showing the value of Sine(x) for values of X between 0 and 360 degrees. + + .EXAMPLE + > + PS> Invoke-Sqlcmd -ServerInstance localhost\DEFAULT -Database AdventureWorks2014 -Query "select * from sys.tables" -OutputAs DataRows | + Export-Excel -Path .\SysTables_AdventureWorks2014.xlsx -WorksheetName Tables + + Runs a query against a SQL Server database and outputs the resulting rows DataRows using the -OutputAs parameter. + The results are then piped to the Export-Excel function. + NOTE: You need to install the SqlServer module from the PowerShell Gallery in oder to get the -OutputAs parameter for the Invoke-Sqlcmd cmdlet. + .LINK https://github.com/dfinke/ImportExcel #>