Invoke-Sqlcmd is Now Available for MacOS & Linux in the SqlServer module. The module has been posted as v21.1.18095-preview which means to download the module you’ll have to add the -AllowPrerelease parameter.
Update-Module SqlServer -AllowPrerelease
But wait, there’s more. In order to use the Invoke-Sqlcmd cmdlet on PSCore you’ll also need to download PSCore 6.2 which, as of this writing, is currently in Release Candidate status. I guess that makes this sort of a double-preview
For information on how to “installing a PowerShell Core Preview release for Linux” check out the docs page.
If you’re on a Mac, you’ll currently need to run pwsh-preview to launch v6.2 of PSCore. Once you have the module updated & PSCorev6.2 installed you’re ready to go. Nothing else needed.
To install PSCore v6.2 on MacOS, after you have run ‘brew cask install powershell’ then run the following code to allow it to access the preview version:
brew tap homebrew/cask-versions
After that, run this to install the preview version of PSCore:
brew cask install powershell-preview
Finally, to launch the preview version of PSCore run the command below and off you go
If you’re still on an earlier version of PSCore and are unable to install PSCore 6.2 right now, you can still download preview of the SqlServer module to get the latest fixes and new features. You just won’t be able to use the Invoke-Sqlcmd cmdlet.
Another quick thing to note is that this is like a v.0.0.1 of Invoke-SqlCmd on PSCore; it does not have all the bells & whistles of the version of Invoke-Sqlcmd for [full blown] Windows PowerShell. Obviously, more features will be added over time, but the basic functionality was ready to for customers to start “kicking the tires”.
The functionality listed in the release notes notes are as follows:
“* Initial support for Invoke-Sqlcmd on .Net Core (-Variable, -DisableVariables, -DisableCommand,
-QueryTimeout, -ConnectionTimeout, -Hostname not supported yet). ”
If you run into an issue with the cmdlet, please do comment on the PowerShell Gallery page for the SqlServer module, Matteo is really good about responding there.
I just pushed out a new (prerelease) version of the SQLServer PowerShell module at https://t.co/mnYCjyVouu.
Surprise, surprise! If you are on PowerShell 6.2.0 (also preview), you’ll be able to run Invoke-Sqlcmd (basic functionality).
— Matteo Taveggia (@matteo_taveggia) March 5, 2019