Share via

Issue with Powershell 7.2 SqlServer module

Shwetha J 15 Reputation points
2024-02-22T04:11:24.68+00:00

I've installed the SqlServer module into Azure runbooks for powershell 7.2 but when I go to use it I get... "Invoke-Sqlcmd' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." Runs on powershell 5.1 no problem

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ryan Hill 30,331 Reputation points Microsoft Employee Moderator
    2024-02-23T01:26:45.9533333+00:00

    Hi @Shwetha J
    I was not able to get this to work and the SqlServer module running on Automation Account PowerShell 7.2 is a known issue. Attempting to install the module resulted in

    Error: 
    Install-Module: 
    Line |
       2 |  Install-Module SqlServer -AllowClobber -SkipPublisherCheck -Force -Sc …
         |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
    

    Installing the Nuget-based provider via Install-PackageProvider -Name NuGet -Force didn't resolve the issue either. Checking PowerShell Gallery | SqlServer.psm1 22.2.0 shows that 22.2.0 requires PowerShell 7.2.1 or higher. Even though I wasn't getting this message and considering that it does work in PowerShell 5.1, I'm inclined to think that currently the SqlServer module is not supported in 7.2 for Automation Account, as others have stated in this open GitHub issue.

    2 people found this answer helpful.

  2. Rich Matheisen 48,036 Reputation points
    2024-03-18T22:49:06.3566667+00:00

    Rather than running version 5.1, try adding the -UseWindowsPowerShell switch to the Import-Module cmdlet.

    PowerShell 7 uses only CORE elements .Net and many modules require more extensive coverage.

    Note that PowerShell versions before version 6 are Windows version of PowerShell, Version 6 and 7 are cross-platform versions with no dependencies on Windows.

    1 person found this answer helpful.

  3. Vahid Ghafarpour 23,600 Reputation points Volunteer Moderator
    2024-02-22T05:10:29.5133333+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    Ensure that the SqlServer module is installed in your Azure environment

    Install-Module SqlServer

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.