Powershell sql server module 2017 manual install - sql-server

Just installed sql server 2017 RTM. After that I installed SSMS version 17. Funny enough this won't install the powershell module but you have to install it from PowerShell Gallery. Now my servers of course (being an enterprise environment) have no direct connection to the internet and not even the management computers in that domain have. From the Powershell Gallery website I was not able to manually install the powershell module. Question is do anybody here managed to have latest sql server powershell module installed for sql server 2017?

I'm not in an environment to test this but one method would be to install the module on a computer/server that does have access to the internet, download and install it there, locate the module, and then copy it to the other server and import it. So, something like:
On the other computer (with internet access):
Install-Module -Name SqlServer
(Get-Module -ListAvailable SqlServer).Path
Go to the path and copy the file(s) to the same location on the other server. Then, on the other server, and run:
Import-Module -Name SqlServer
This assumes that both hosts are running the same version of Powershell; or at least compatible ones.

Related

Install SQL Server LocalDB on Server Core 2019 in Docker container

Within a Docker container (image = mcr.microsoft.com/windows/servercore:ltsc2019), I have downloaded the SQL Server Express 2019 installer.
I have successfully downloaded the LocalDB msi with:
SQL2019-SSEI-Expr.exe /Action=Download /MediaType=LocalDB /Quiet
The file is downloaded to:
C:\Users\ContainerAdministrator\Downloads\en-us\SqlLocalDB.msi
However... running msiexec fails without any error messages. After navigating to the path mentioned above, I execute:
msiexec.exe /qb /i .\SqlLocalDB.msi IAcceptSqlLocalDBLicenseTerms=YES
The command immediately drops back to the command line after zero delay. Nothing ever gets installed.
What am I missing?
Edit:
I'm trying to use LocalDB because this will eventually be an Azure Pipelines build agent. We use Redgate's "SqlChangeAutomation" powershell tools which uses LocalDB.
Edit 2:
Not sure if this is progress yet, however... I mucked around with msiexec logging for a bit and discovered I could run it with the /a flag instead of /i and get it to successfully install.
msiexec.exe /qn /a SqlLocalDB.msi IAcceptSqlServerLicenseTerms=YES /L*V "C:\installers\SQL\install.log"
Unfortunately, however, upon navigating to C:\Program Files\Microsoft SQL Server\150\tools\binn and running SqlLocalDB.exe info, I get this:
Call to LocalDBFormatMessage failed. Error code returned:
2311389462.
Error in LocalDBFormatMessage! Error code returned:
2311389462.
SQL LocalDB requires the Visual C++ redistributables, else many things won't go right (my problem was that SqlWriter service wouldn't create during install at all).
EDIT: it seems that I can use chocolatey to install the vc_redist and a older version of localdb. (Filing ticket to ask for the sqllocaldb package to be updated to 2019) so that would simplify things for most people. Keeping raw arguments/commands below just in case though.
My powershell steps for exact arguments (assuming you collect required files):
start-process .\VC_redist.x64.exe -Wait -ArgumentList #('/install','/norestart','/passive') Note I am using the redist from https://aka.ms/vs/16/release/vc_redist.x64.exe which should be the 2019, but spattering of comments say I should have used either the one in the SQL installer package, or some 2015 version. However neither of those "worked" for me in the containers, but that could have been me invoking them wrong. Besides which, further packages I need to install want 2019 anyways.
start-process msiexec -Wait -ArgumentList #('/i','SqlLocalDB.msi','/qn','/norestart','/L*V','install.log','IACCEPTSQLLOCALDBLICENSETE RMS=YES') Note that "/i" instead of "/a" worked correctly at this point, and the "/norestart" option. This was found from the choco localdb command source.
Useful powershell snippet to get some event logs (change "System" for "Application" for others) that helped me puzzle things out since no event-viewer in container: get-eventlog -LogName System -After (Get-Date).AddMinutes(-5) | ? {-not $_.Source.Contains("DCOM") } |?{-not $_.Message.Contains("depends on the Background Tasks Infrastructure Service")}| Format-List This and inspecting the "install.log" line-by-line from the SqlLocalDB.msi were what eventually led me on the right track.
I was trying to create images for pipelines too, installing via chocolatey, so I simply installed the chocolatey package for the redistributable too and that resolved the issue:
choco install vcredist-all -y
choco install sqllocaldb -y

SQL Server 2019 Express installation failed because it could not find the 2017 driver?

I installed the basic configuration of SQL Server 2019 and got an error at the end:
Oops
Unable to install SQL Server (setup.exe).
Exit code (Decimal): -2068052310
Error description: An installation package for the product Microsoft
ODBC Driver 17 for SQL Server cannot be found. Try the installation
again using a valid copy of the installation package 'msodbcsql.msi'.
I have the log file if this is helpful. I'm mystified why it's looking for this driver.
OS: Windows 10 Home
I had the same error, just download the package here and then run again the SQL Express installer.
Have you already install SQL Server on this computer? If yes - try uninstall this driver, and then install SQL Server again.
I remove the setup of the SQL server application and my ODBC driver
then I setup:
SQL server 2019
and SSMS:SQL server management system
You need to download Microsoft ODBC Driver for SQL here: https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15
Mine worked, after I deleted the folder that it created at:
C:\Program Files (x86)\Microsoft SQL Server
Then I reran the installation file.
Open the Windows Powershell as administrator and execute this:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type Dword
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type Dword

SQL Powershell Module is not installed on your agent machine. Please follow steps given below to execute this task

We're using TFS 2018 (Update3.2) to do continuous integration and deployment. I have a release definition where we do a SQL deployment (run a SQL file) and IIS deployment.
IIS deployment works but the SQL deployment fails saying "SQL Powershell Module is not installed on your agent machine...". I installed the SQL Server PowerShell module, restarted the server, recreated the agent but still getting the same error. SQL PowerShell module is installed on the TFS and web server. Does it have to be installed on SQL server as well? Am I missing anything? Please help.
SQL Powershell Module is not installed on your agent machine. Please follow steps given below to execute this task.
Testing the same steps, I also encountered this issue. To solve this issue, you need to install sql server module. (Script Install-Module -Name SqlServer)
From you comment, you have added this module but still have this issue.
You could try the following steps:
Uninstall the module(Uninstall-module -Name SQLServer). Then re-install the module for all users.
Install-Module -Name SqlServer -Scope AllUsers
Restart the Agent Service in Local System-> Services.
After these steps, you could run the build again and check if it could work.
In addition,you also could create a new target agent in Deployment Group.
From this ticket, the new agent seems to solve this issue.
Hope this helps.
I had to install SqlPackage.exe also for it to work.
Here are the steps I followed:
Install SqlPackage.exe (x86 and x64)
Install SQL Server PowerShell module
Restart the Agent Service

PowerShell v5.1 - Loading SqlServer Module does not load Read-SqlTableData or Write-SqlTableData, but Loads All Other Commands

On my Windows Server 2012 R2 server, the same server as my SQL Server service instance is running, I had upgraded to PowerShell v5.1. I proceeded to load the SqlServer module v21.1.18121. All commands loaded fine except for Read-SqlTableData and Write-SqlTableData. The darndest thing! When I load the same SqlServer module on my Win10 development box, all commands are present. I suspect something like a version problem with the available .Net framework or some such, or a collision with SQL Server's modules. Anyone with thoughts on this one?
The SqlServer module comes with the SQL Server installation and thems to be in a different version.
Module location on a SQL Server
(Get-Module -l SqlServer).path
-> C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psd1
Module location from PowerSehll gallery
(Get-Module -l SqlServer).path
-> C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.0.17279\SqlServer.psd1
You can enforce PowerSell to load a module from specific location
Install-Module -Name SqlServer
Import-Module -Name (Get-Module -l SqlServer).path -Verbose
I've just encountered the same problem. I've tried many things, but I think the problem stems from having the module SQLPS installed alongside SqlServer module. (SQLPS being an older version of sqlserver).
The steps I used: (probably a little excessive)
Close every application that may have a reference to Powershell
modules. For me this list included Visual Studio, SSMS, SQL Agent,
and of course all Powershell cmd and/or IDE.
Open a Administrator PowerShell command shell.
execute:
Uninstall-Module sqlps
Uninstall-Module sqlserver
Check the Powershell modules folder to make sure you've cleared the modules.
The place to look is:
ls "c:\program files\WindowsPowerShell\Modules"
Both of the folders "sqlps" and "sqlserver" should be missing or empty.
Now re-install sqlserver module:
Install-Module sqlserver
Check that you have the Write-SqlTableData:
Get-Command -module sqlserver
In case you suspect you have an error with versioning: I have tried and tested sqlserver module versions: 21.1.18218 & 21.0.17099

Import-Module : The specified module 'SqlServer' was not loaded because no valid module file was found in any module directory

Well, hello there!
I'm working on a Script to get the Sql Job History and need to use the "SqlServer" Module. It's installed but I can't import it due to the Error Message above. When I got to the Modules Path, the Folder "SqlServer" exists and isn't empty. Don't get the problem here.
Thanks in advance!
I just ran into this on SQL Server 2017 (on Windows Server 2016) and found your question in the process. I then went and fired up our older SQL Server 2014 (Windows Server 2012) machine and found the same issue. Here's a couple options everyone can try to save some time (as I realize the question is kind of old and I'm assuming the OP found a solution already):
1) At a powershell command run: Install-Module -Name SqlServer (you might need -AllowClobber parameter)
The thing here is that module is installed to the following path on both 2012 and 2016 servers:
C:\Program Files\WindowsPowerShell\Modules\SqlServer (rather than Microsoft SQL
Server\120\Tools\PowerShell\Modules)
2) Another option is to try the SQLPS module by changing in your script:
Import-Module -Name SqlServer
To:
Import-Module -Name SQLPS
You will find SQLPS in the Microsoft SQL Server directory structure here:
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules
My script works with both SQL modules now, but the output actually looks better with SQLPS at this point...
You can find more on all of the above at this link
With TLS v1.0 and v1.1 being deprecated on Microsoft Services services in 2022/Q2, this error comes up again on non-updated Windows and/or PS versions.
The issue is solved by forcing PS to use TLS v1.2 and an updated NuGet version ...
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
... before running Import-Module -Name SqlServer.
As pointed out at this related question in DBA/StackExchange.

Resources