SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Exporting data with header using Powershell


Exporting data with header using Powershell

Author
Message
Louis Li
Louis Li
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 258
Comments posted to this topic are about the item Exporting data with header using Powershell

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
swebster
swebster
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 4
I really wish I understood what this script is doing. To me, the article assumes the reader already knows a lot of what is being referred to.
I can write queries, but I have never used Powershell, and I can't make heads or tails out of these directions.
I do have a query with results that I would like to export to a file (although I want it tab-delimited, not comma separated), but I would need the directions to be more explanatory than this.
Louis Li
Louis Li
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 258
swebster (4/28/2014)
I really wish I understood what this script is doing. To me, the article assumes the reader already knows a lot of what is being referred to.
I can write queries, but I have never used Powershell, and I can't make heads or tails out of these directions.
I do have a query with results that I would like to export to a file (although I want it tab-delimited, not comma separated), but I would need the directions to be more explanatory than this.


Hi swebster, take a look at this:
http://rrlmblog.wordpress.com/2014/04/29/step-by-step-extracting-data-from-sql-server-using-powershell/

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
Shawn Melton
Shawn Melton
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5575 Visits: 3536
swebster (4/28/2014)
I really wish I understood what this script is doing. To me, the article assumes the reader already knows a lot of what is being referred to.
I can write queries, but I have never used Powershell, and I can't make heads or tails out of these directions.
I do have a query with results that I would like to export to a file (although I want it tab-delimited, not comma separated), but I would need the directions to be more explanatory than this.

There are much easier methods of getting information out of SQL Server with SQL Server PowerShell. Most folks tend to go towards using SMO or .NET data reader objects.

A basic example of how I generally pull out information to manipulate in PowerShell

#need to import the module used by SQL Server 2012 in order to access the Invoke-Sqlcmd commandlet
Import-Module SQLPS
#if working with SQL Server 2008 - SQL Server 2008 R2 use:
# Add-PSSnapin *SQL*

#This is a here-string and supports variables that contain multi-line strings
$q = @"
SELECT name, database_id
FROM sys.databases
GO
"@

#capturing the data into a variable
$results = Invoke-Sqlcmd -ServerInstance ORKO -Database master -Query $q

# export the results straight to your tab delimited CSV file
$results | Export-Csv -Path 'C:\Temp\TestInfo.cvs' -Delimiter "`t" -NoTypeInformation




Shawn Melton
Twitter: @wsmelton
Blog: blog.wsmelton.info
swebster
swebster
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 4
Louis and Shawn,
Thanks!
Scott
amitsingh.gniit
amitsingh.gniit
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 292
When i am trying to run the script through sql server agent it is showing given error. Could any body can suggest how i can run this by using sql server agent .

Executed as user: HOMEPC\SYSTEM. A job step received an error at line 2 in a PowerShell script. The corresponding line is 'write-host $args.Count'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot invoke this function because the current host does not implement it. '. Process Exit Code -1. The step failed.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search