Can anyone help me on below . I am trying to execute the SQLCMD with DAC (-A switch) but unable to do so .

How can I do it both ways below :

  1. Execute in SSMS Query Pane
  2. Execute using PowerShell

Below is what I have tried with no luck .

EXEC master.dbo.xp_cmdshell "SQLCMD -S SQLServer -d Db1 -A
select count(*) AS FileCount from TableName


'select' is not recognized as an internal or external command, operable program or batch file. NULL


Msg 103, Level 15, State 4, Line 1 The identifier that starts with '

SQLCMD -S SQLServer -d Db1 -A
select count(*) AS FileCount' is too long. Maximum length is 128. 
  • 2
    Quick question: Why do you want to run a command in SSMS via SQLCMD with DAC? Why not just open a query window with DAC?
    – John K. N.
    Jan 8, 2018 at 7:44
  • @hot2use , I am trying to check filecount which are marked in FileStream Garbage collection tombstone table which needs to accessed only by DAC connection. When I tried to access ADMIN:Server , it is somewhat saying me , it cannot connect . In this case I am using SQLCMD with -A switch . Same thing I am trying to do it with powershell which I am not able to . So I am looking for ways to execute multiple line of code using SSMS and even powershell . Many thanks Jan 8, 2018 at 8:57

1 Answer 1


You should pass in your query according to sqlcmd syntax specifying -Q (or -q or -i for the script file) like this:

EXEC master.dbo.xp_cmdshell 'SQLCMD -S SQLServer -A -d Db1 -Q"select count(*) AS FileCount from TableName" '
  • Thanks , this did help me . Anyways which I can do the same thing in Windows PowerShell . For ex : How can I execute SQLCMD from Invoke-SQLCMD ? Many thanks Jan 8, 2018 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.