ernestoacostacuba
Posts: 3
Joined: Fri Aug 02, 2024 3:54 pm

Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Hello everyone,

I'm using Advanced Installer to create a .msi project to install SQL Server Express 2022 silently. In the "Files and Folders" page I add the .exe for SQL Server Express 2022 and a PowerShell script inside the "Application Folder" that has the "APPDIR" identifier. Then I created a "Launch File" custom action specifying [APPDIR]SqlServerExpressSilentSetup.ps1 as value for the "File to launch" field and "-ExecutionPolicy Bypass -File "[APPDIR]SqlServerExpressSilentSetup.ps1" -InstanceName "VRS" for the "Command line" field.
The content of the powershell script is this one:
param (
[string]$InstanceName = "VRS"
)

if (-not $InstanceName) {
Write-Output "InstanceName parameter is required."
exit 1
}

# Define the path to the SQL Server setup executable
$setupPath = Join-Path -Path $PSScriptRoot -ChildPath "SQLEXPR_x64_ENU.exe"

# Define the SQL Server installation command
$installArgs = "/x:.\ExtractionFolder /Q /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQLEngine /INSTANCENAME=$InstanceName /SQLSYSADMINACCOUNTS=`"$env:USERDOMAIN\$env:USERNAME`""

# Execute the SQL Server installation command
Write-Output "Starting SQL Server installation..."
Start-Process -FilePath $setupPath -ArgumentList $installArgs -Wait

Write-Output "Script execution completed."

Once I run the .msi file at some point I got a popup with this error:
"Windows cannot find 'C:\MSC Technology\VRSv1\SqlServerExpressSilentSetup.ps1'. Make sure you typed the name correctly and then try again.

Someone can help me to fix this issue that I'm facing, please?

Thanks in advance.
Catalin
Posts: 7664
Joined: Wed Jun 13, 2018 7:49 am

Re: Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Hello and welcome to our forums,

Could you please let me know where you have scheduled your custom action?

From the looks of it, you have scheduled it before the files are actually copied on the disk.

In addition to that, could you please let me know why you are not using our predefined support for Prerequisites?

Installing another product through a script can prove challenging considering the limitation of Windows that does not allow two installations to happen at the same time on the same machine.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ernestoacostacuba
Posts: 3
Joined: Fri Aug 02, 2024 3:54 pm

Re: Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Catalin wrote: Tue Aug 06, 2024 4:10 pm Hello and welcome to our forums,

Could you please let me know where you have scheduled your custom action?

From the looks of it, you have scheduled it before the files are actually copied on the disk.

In addition to that, could you please let me know why you are not using our predefined support for Prerequisites?

Installing another product through a script can prove challenging considering the limitation of Windows that does not allow two installations to happen at the same time on the same machine.

Best regards,
Catalin
Hello,
Thanks in advance for your support.
OK.... I got your explanation and now I was able to install SQL Server Express 2022 adding it as prerequisite.
My problem now is another one:
Inside my project in Advanced Installer I created a "Run PowerShell script file" custom action to execute a powerhsell script II put in the "TemporaryFolder" in the "Files and Folders" page.
The scope of this script is to restore a database, but once I launch the .msi, from the logs I got this error:
[INFO] PowerShell script preferred invocation folder:
Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 0
--> PowerShell Script Execution log:
Backup File Path: C:\Users\ERNEST~1.ROD\AppData\Local\Temp\VesselReportingSystem.bak
Database Name: VesselReportingSystem
SQL Server: VRS20
Hostname: hqapew1rpF4UF8Z
Full SQL Server Instance: hqapew1rpF4UF8Z\VRS20
Restoring the database...
File: C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\sqlcmd.exe
Msg 262, Level 14, State 1, Server hqapew1rpF4UF8Z\VRS20, Line 1
CREATE DATABASE permission denied in database 'master'.

The weird thing is that if i take the powershell script and I execute it from a PowerShell terminal (with admin privileges) everything works fine, and the database is restored.

Would you be kind to help me with this issue, please?

Thanks in advance.
Catalin
Posts: 7664
Joined: Wed Jun 13, 2018 7:49 am

Re: Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Hello,

You are always welcome! I am glad to hear you managed to install SQL Express now. :)
Would you be kind to help me with this issue, please?
Sure thing. As per my understanding, your custom action is not elevated.

What we can do in order to elevate our PowerShell script is:

- change its execution time to "when the system is being modified (deferred)"

- check the "Run under the LocalSystem account with full privileges (no impersonation)" option

Note: in order for you to be able to set your PS script as "deferred", you will have to schedule it after the "Preparing" action group at a minimum.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ernestoacostacuba
Posts: 3
Joined: Fri Aug 02, 2024 3:54 pm

Re: Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Good morning,
At the moment I put apart the option to install SQL Server Express 2022 using a PowerShell script and I'm using the "Prerequisites" feature.
For this, I have two prerequisites:
- SQL Server Express 2022
- Microsoft .NET 8.0.7 - Windows Server Hosting

The "SQL Server Express 2022" prerequisite appears under the "Packages" root and the other one, appears within the "Main Package" directory.

In the "Installation" tab for "SQL Server Express 2022" I configure it like this:

UI level: Silent Install (no UI)
Command line: /UpdateEnabled=False [AI_PREREQ_UILEVEL_SWITCH] /INSTANCENAME="VRS"

This command line is the same for the others UI levels.

In the "Conditions" tab I flagged "Always install prerequisite"

Once I build the .mis and launch it, it roll backs at the end and when I see the log, there is not any clue regarding the installation of the SQL Server Express 20022. Instead, the "Microsoft .NET 8.0.7 - Windows Server Hosting" is installed.


I'm not able to understand why the SQL Server Express 2022 is not installed.

From the log I got this:

Action 7:47:55: VrsDatabaseRestore.
Action start 7:47:55: VrsDatabaseRestore.
MSI (s) (18:38) [07:47:55:947]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI1CA.tmp, Entrypoint: RunPowerShellFileScript
[INFO] PowerShell script preferred invocation folder:
Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 1
--> PowerShell Script Execution log:
Restoring the database...
Executing command: & "C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\sqlcmd.exe" -S hqapew1rpF4UF8Z\VRS -E -Q "RESTORE DATABASE [VesselReportingSystem] FROM DISK = 'C:\ProgramData\VesselReportingSystem1.bak' WITH MOVE 'VesselReportingSystem' TO 'C:\ProgramData\MSC\VesselReportingSystem\DATA\VesselReportingSystem.mdf', MOVE 'VesselReportingSystem_log' TO 'C:\ProgramData\MSC\VesselReportingSystem\DATA\VesselReportingSystem_log.ldf'"
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
MSI (s) (18!18) [07:48:04:482]: PROPERTY CHANGE: Adding POWERSHELL_EXECUTION_LOG property. Its value is 'Restoring the database...
Executing command: & "C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\sqlcmd.exe" -S hqapew1rpF4UF8Z\VRS -E -Q "RESTORE DATABASE [VesselReportingSystem] FROM DISK = 'C:\ProgramData\VesselReportingSystem1.bak' WITH MOVE 'VesselReportingSystem' TO 'C:\ProgramData\MSC\VesselReportingSystem\DATA\VesselReportingSystem.mdf', MOVE 'VesselReportingSystem_log' TO 'C:\ProgramData\MSC\VesselReportingSystem\DATA\VesselReportingSystem_log.ldf'"
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote

Would you be kind to help me with this issue, please?

Thanks in advance.
Catalin
Posts: 7664
Joined: Wed Jun 13, 2018 7:49 am

Re: Unable to install SQL Server Express 2022 in silent mode using a PowerSell script

Hello,

From the looks of it, you are having troubles with your restore custom action, which seems to fail.

Since this is custom code, it's really hard for me to help debug it.

If the SQL Server is not installed when you try to execute that custom action, then this might be a possible cause for this.

Do you launch the entire installer silently, by any chance?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”