invoke-sqlcmd

Invoke-sqlcmd output without “quotes” and headers

左心房为你撑大大i 提交于 2020-08-08 04:42:49
问题 Output example: #TYPE System.Data.DataRow <--- "PersonalNr" <--- "00001005" "00001008" "00001009" "00001013" "00001019" "00001024" Requirements: I want a output without the 2 first lines and without the quote symbols, how can i do that? For the headers I tried the options -h -1 but the output is still the same. Is it even possible with Sqlcmd ? Current Code: Invoke-Sqlcmd -ServerInstance SERVER -h -1 -Query $QueryFmt | Export-CSV $AttachmentPath 回答1: This code should work: Invoke-Sqlcmd

Invoke-Sqlcmd not working in SQL

筅森魡賤 提交于 2020-01-17 03:07:28
问题 Im using the following command in SQL Powershell to generate csv of data returned by SQL. Invoke-Sqlcmd -Query "myp" -ServerInstance "." | Export-Csv -Path "d:\data\MyDatabaseSizes.csv" -NoTypeInformation The above command works perfectly fine in SQL Power Shell. but when I tried to run in from SQL using the following code DECLARE @cmd varchar(1000) SET @cmd = 'Invoke-Sqlcmd -Query "myp" -ServerInstance "." | Export-Csv -Path "d:\data\MyDatabaseSizes.csv" -NoTypeInformation' EXEC xp_cmdshell

Outputting large XML file from SQL with Powershell

↘锁芯ラ 提交于 2019-12-25 01:16:33
问题 I have a Powershell script that calls a stored procedure in SQL server and outputs the resulting XML directly to a file. It works for a smaller test file but falls down with the full size (~1.5gb file). The stored procedure works fine. I can call it within SQL server - the problem is that I have to open it in the SQL server then manually save it to a file, then edit that file to remove newlines. When I run the script it falls down when it tries to delete the intermediary files at the end.

Powershell - SQL query result to variable with properties

隐身守侯 提交于 2019-12-11 04:23:57
问题 Why the stored output of SQLCMD has only Length property instead of column names ?. Is it not possible to store sqlcmd output with its properties? Invoke-sqlcmd stores it correctly but Invoke-SQLcmd takes a bit longer to process so I'm trying to make it work with SQLcmd as this method will be part of different scripts that are scheduled to run every minute, once ever hour etc., Any idea if this is possible or what the issue is? Store output and echo $var: PS C:> $var=(SQLCMD -S 'x.x.x.x' -U

Escape variable in sqlcmd / Invoke-SqlCmd

戏子无情 提交于 2019-12-10 17:34:03
问题 I am using powershell and using Invoke-SqlCmd. I am able to pass variables to SQL: $variables = @( "MyVariable='hello'" ) Invoke-SqlCmd ` -ServerInstance 'localhost' ` -Database 'master' ` -Username 'matthew' ` -Password 'qwerty' ` -Query 'SELECT $(MyVariable) AS foo' ` -Variable $variables This gives me back hello as expected. However, if I have a variable with a value containing an equals ( = ): $variables = @("MyVariable='aGVsbG8NCg=='") # base64 encoded 'hello' It gives me the following

PowerShell: invoke-sqlcmd with Get-Credential doesn't work

▼魔方 西西 提交于 2019-12-08 02:58:30
问题 I've never seen a so easy script failing so royally: $SQLServer = "localhost" $cred = Get-Credential invoke-sqlcmd -ServerInstance $SQLServer -Credential $cred -Query "select @@version" the phrase says -Credentials is not recognized: Invoke-Sqlcmd : A parameter cannot be found that matches parameter name 'Credential'. So what is the point to have Get-Credential ? I see a lot of examples on internet and they all use it this way. EDIT EXAMPLE: why this code is working with -Credential ? Because

Invoke-Sqlcmd unable to run

北战南征 提交于 2019-12-07 04:56:44
问题 I have a PowerShell script that checks the CPU level of the server it is running on, and then if it is above a certain threshold it will run a SQL stored procedure and e-mail. The script runs correctly on my development server with the latest version of PowerShell. However, I am having issues running the Invoke-Sqlcmd command on the live server I need to get the CPU values from. For sake of example it can be called LIVESERVER. It is running PowerShell 2.0 which I think is the issue: The term

Unable to load adalsql.dll error when calling `Invoke-sqlcmd`

萝らか妹 提交于 2019-12-03 10:56:25
问题 I have VS2015 with SSDT installed, along with SSMS and the SqlServer PowerShell module (which includes the invoke-sqlcmd comand), and yet If I try to execute a query against an Azure SQL Data Warehouse like so: invoke-sqlcmd -Query "Select top 5 * from customer" -ConnectionString "Server=tcp:my.database.windows.net,1433;Database=Customer; Authentication=Active Directory Integrated; Encrypt=True; " I get the following error: invoke-sqlcmd : Unable to load adalsql.dll (Authentication

PowerShell invoke-sqlcmd Get-ChildItem : Cannot call method. The provider does not support the use of filters

一个人想着一个人 提交于 2019-12-02 09:16:08
问题 I have a strange error occurring when using the invoke-sqlcmd to insert rows into a table. The entire script works perfectly if executed one time, but if I run it a second time, it fails with the error message: Get-ChildItem : Cannot call method. The provider does not support the use of filters. I tested the code and commented out the invoke-sqlcmd line, and can run it multiple times without any errors. I put the invoke-sqlcmd in a function and it still errors, and after the first successful

PowerShell invoke-sqlcmd Get-ChildItem : Cannot call method. The provider does not support the use of filters

陌路散爱 提交于 2019-12-02 04:32:12
I have a strange error occurring when using the invoke-sqlcmd to insert rows into a table. The entire script works perfectly if executed one time, but if I run it a second time, it fails with the error message: Get-ChildItem : Cannot call method. The provider does not support the use of filters. I tested the code and commented out the invoke-sqlcmd line, and can run it multiple times without any errors. I put the invoke-sqlcmd in a function and it still errors, and after the first successful run it will fail at the PS command line too. Clear-Host $ErrorActionPreference = 'Stop' function Update