Questions tagged [invoke-sqlcmd]

PowerShell cmdlet that runs a script containing statements from the languages (Transact-SQL and XQuery) and commands supported by the SQL Server sqlcmd utility.

For MicroSoft's official documentation on this cmdlet see: https://msdn.microsoft.com/en-GB/library/cc281720.aspx

Alternative options to this command exist. For a discussion of these see: https://dba.stackexchange.com/questions/17435/which-powershell-technique-should-i-use-to-talk-to-sql-server

148 questions
0
votes
1 answer

after running invoke-sqlcmd why is the fileSystem provider required to access UNC Server paths

after reading the following link I was able to resolve my own issue - but does anyone know why the FileSystem Provider is required here after using invoke-sqlcmd ie. why does the following fail $Doc_Folder = "\\Server.fqdn.com\c$\DocFiles"…
Gene Lowy
  • 15
  • 5
0
votes
1 answer

Invoke-Sqlcmd : Conversion failed when converting date and/or time from character string

My PowerShell script keeps failing when trying to import a CSV file. The error message reads: "Invoke-Sqlcmd : Conversion failed when converting date and/or time from character string." In my CSV file, I have a column called "LastWriteTime" Here is…
Sheldon Lewis
  • 35
  • 1
  • 5
0
votes
1 answer

How do you specify the region/language/culture settings when invoking sqlcmd in Powershell?

When I execute a function that returns a datetime (like GETDATE()) in SQL Server Management Studio the output is formatted in the user's "culture" (region/language settings). However when that same query is executed in Powershell through the…
Bram
  • 819
  • 1
  • 9
  • 24
0
votes
1 answer

Invoke-Sqlcmd on multiple computers powershell for serverproperty edition

I am trying to run the below command: "SQL Version" = (Invoke-Command -ComputerName $Computer -ScriptBlock { Invoke-Sqlcmd -Query "SELECT SERVERPROPERTY ('edition')"}) The Output just shows: SQL Version : System.Data.DataRow How…
onefiscus
  • 129
  • 1
  • 3
  • 15
0
votes
1 answer

Invoke-Sqlcmd2 do not terminate on error

Is there any way to make the function Invoke-Sqlcmd2 not terminate the rest of the script on failure? I want the rest of my script to continue to run even if this command fails. I've dug around the code and my thought is it has something to do with…
Mike
  • 43
  • 1
  • 3
  • 7
0
votes
1 answer

How to run Invoke-SQLCMD cmdlet in non interactive mode

Invoke-SQLCMD cmdlet does not work when executed through powershell script (.ps1) Following error is logged: [error]Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. [error]Process completed with…
Santhosh
  • 671
  • 12
  • 36
0
votes
1 answer

Invoke-Sqlcmd not working in SQL

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…
Muhammad Taqi
  • 305
  • 2
  • 6
  • 19
0
votes
1 answer

Specify partial directory to use in Powershell Invoke sqlcmd

Need to be able to run .sql files individually that are located in multiple sub directories. This script will be ran on multiple computers where the directory wont be the same but the sub directories will be. So I want to be able to define the…
Harvdawg
  • 75
  • 6
0
votes
2 answers

Powershell SqlPs module not importing properly

I have a (pretty much clean) Windows Server 2008 R2 Build with SQL Server 2012 installed. I'm having a problem with PowerShell (Version 3). I am trying to use the Invoke-Sqlcmd cmdlet. However, when I call get it i get a message saying that…
0
votes
1 answer

Powershell Invoke-Sqlcmd and multiple select statements within the input

The problem I am facing lies with the use of the invoke-sqlcmd command below $result = Invoke-Sqlcmd -InputFile $sqlfile -ServerInstance $DB The example sql within $sqlfile is: SELECT TOP 2 FROM [TABLE1] SELECT TOP 3 FROM [TABLE2] The kind of…
Inammathe
  • 103
  • 1
  • 5
0
votes
1 answer

SQL Server - Single User Mode - Persist Which User

Question Is there a way, when putting a database into single user mode, to specify that user (in my case it is the current user), and to ensure that even after that user disconnects, the single session kept reserved for that defined user; i.e. so it…
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
-1
votes
1 answer

Invoke-Sqlcmd returning error: 40 - Could not open a connection to SQL Server

I am trying to use Invoke-Sqlcmd command in PowerShell (version 7): $Server = 'localhost' $Database = 'db' $Query = "PRINT 'This is output'" $Username = 'root' $Password = 'pass' Invoke-SQLCmd -ServerInstance $Server -Database $Database…
-2
votes
1 answer

How To Prevent Invoke-SQLCMD from trimming Leading Zero's

In powershell I have a script and every time it runs it needs to increment a number in a DB by one. Once it reaches 9999 it resets back to 0001. I have this functionality worked out in powershell my issue is that Invoke-SQLCMD keeps stripping out…
1 2 3
9
10