locked
unknown command invoke-sqlcmd RRS feed

  • Question

  • Hey guys.  So I have this .bat file which automates the installation of SQL Server.  Towards the end of the script, I'm trying to execute a powershell script which calls a SQL Scripts to install objects in our new instance(highlighted in bold below).

    @echo off
    pushd %0\..\
    If NOT Exist C:\Temp\SQL2012 md C:\Temp\SQL2012
    xcopy /E /I /H /R *.* C:\Temp\SQL2012
    cd /d C:\Temp\SQL2012
    If NOT Exist D: powershell -File C:\Temp\SQL2012\DiskPart.ps1
    setup.exe /configurationfile=SQL2K12.ini /iacceptsqlserverlicenseterms
    echo Return code: %ERRORLEVEL%
    pause
    powershell -File C:\Temp\SQL2012\Updates\standards.ps1
    pause
    popd

    Problem is that when the powershell script tries to execute, it gives me an error saying that it doesn't recognize the invoke-sqlcmd.  So I have another bat file which I run just to test out, and it simply calls the same powershell script, and it works.

    @echo off
    pushd %0\..\
    powershell -File C:\Temp\SQL2012\Updates\standards.ps1
    pause
    popd

    Wednesday, February 25, 2015 1:35 AM

Answers

  • it doesn't recognize the invoke-sqlcmd.  


    The command is only available when the SqlPs commandlet is loaded; see sqlps Utility

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Proposed as answer by dave_gona Wednesday, February 25, 2015 7:14 AM
    • Marked as answer by Papy Normand Saturday, April 25, 2015 7:12 PM
    Wednesday, February 25, 2015 7:06 AM

All replies

  • it doesn't recognize the invoke-sqlcmd.  


    The command is only available when the SqlPs commandlet is loaded; see sqlps Utility

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Proposed as answer by dave_gona Wednesday, February 25, 2015 7:14 AM
    • Marked as answer by Papy Normand Saturday, April 25, 2015 7:12 PM
    Wednesday, February 25, 2015 7:06 AM
  • I run the same command using two different bat files on the same folder.  using the same bat file after the installation it doesn't work, but when I run another bat file with only the powershell part, it works.
    Wednesday, February 25, 2015 2:11 PM
  • load the module before executing the powershell script 

    Import-module sqlps
    --Prashanth


    Wednesday, February 25, 2015 2:20 PM
  • You mean in the bat file or in the actual powershell script?
    Wednesday, February 25, 2015 2:24 PM