Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:29+00:00 2026-06-01T12:04:29+00:00

I had this sqlcmd snippet working in batch but when I converted to powershell,

  • 0

I had this sqlcmd snippet working in batch but when I converted to powershell, it broke. This is what I am attempting to call using powershell

Sqlcmd -S localhost\instance -d database -U username -P password -i "sqlQuery.sql" -s "," > \sqlOutput.csv -I -W -k

I tried invoke-sqlcmd but i get the error “The term ‘invoke-sqlcmd’ is not recognized as the name of a cmdlet, function, script file, or operable program”

In regards to the comment below, I have loaded the snapins required. This did help but I am now getting this error. “Invoke-sqlcmd : Parameter cannot be processed because the parameter name ‘s’ is ambiguous.

If I put it in single quotes…

invoke-Sqlcmd '-S localhost\instance -d database -U username -P password -i "sqlQuery.sql" -s "," > \sqlOutput.csv -I -W -k'

I get the error “A network-related or instance-specific error occurred while establishing a connectiong to sql server. Which doesn’t make sense to me as the same credentials i am using here (on the same box) work when called from batch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:04:30+00:00Added an answer on June 1, 2026 at 12:04 pm

    You have to first call sqlps.exe from powershell or command prompt (assuming you have the SQL Server snap-ins for Powershell installed).

    Once you do that, execute get-help Invoke-Sqlcmd to find your way around.

    To your question, its not -S, but -ServerInstance

     PS SQLSERVER:\> Invoke-Sqlcmd -ServerInstance "srvrName" -Database "master" -Username "user123" -Password "x$34fth" 
    -InputFile "C:\Users\testUser\Desktop\test.sql" | Out-File "C:\Users\testUser\Desktop\out.txt"
    

    You can also use the MSDN documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this working fine while using toggle, but I need to make these
Had this working well in Emacs 23.1.x but it appears to have broke in
I had this simple modal contact form working fine but must have broke it
I had this working previously, but I didn't understand how, so I'm attempting to
I had this working in an old code that I didn’t end up using...
I had this working in prototype.js but it conflicted with a few script files.
I had this working an hour ago but must have changed something. How should
I've had this working for months but I had a power cycle today and
Had this working; at one stage. The problem is the following text is now
I had this nasty bug that disappeared in the past but now after quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.