April 8, 2014 at 9:19 pm
Comments posted to this topic are about the item Exporting data with header using Powershell
April 28, 2014 at 7:53 am
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.
April 28, 2014 at 7:25 pm
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:
April 28, 2014 at 9:17 pm
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: wsmelton.github.com
Github: wsmelton
April 29, 2014 at 7:08 am
Louis and Shawn,
Thanks!
Scott
July 29, 2014 at 2:14 am
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.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy