Search code examples
powershellsql-server-data-toolsssdt-bi

Install arguments breaking an automated PowerShell install


I'm installing SQL Data Tools via a PowerShell script. I run my script, but the final part where the Data Tools are installed fails (inside of the SQL installer window). If I run the script without that part, and install Data Tools manually it works.

The error is:

VS Shell installation has failed with exit code -2147205120.

The parts before this install .NET and SQL Server Management Studio. I don't think they're relevant to my issue, but I will post that part if requested. Here are the relevant parts. The first try block installs SQL SP1 (removed now for readability), the second installs Data Tools and SNAC_SDK.

try
{
    Write-Host "Lauching SQL Server Data Tools install ..."
    & "\\mynetworkpath\SSDTBI_x86_ENU.exe" "/ACTION=INSTALL" "/FEATURES=SSDTBI,SNAC_SDK" "/Q" "/IACCEPTSQLSERVERLICENSETERMS"
    Write-Host "Installer launched ..."
}
catch
{
    Write-Host "SQL Server Data Tools installation failed"
    exit
}

I have tried juggling around the arguments for the Data Tools install part, and playing with the -wait verb to make sure SP1 is done for sure, but no luck.

EDIT: Per Matt's suggestion I added /NORESTART to my argument list, but now it doesn't install anything, and doesn't error either...

EDIT: Added updated code with quoted arguments. Still doesn't work, but I think it's closer than it was originally.


Solution

  • I think the comma in the arguments is the culprit here because powershell interprets entities separated by comma as an array.

    You can see how parameters get passed with this little hack

    & { $args } /ACTION=INSTALL /FEATURES=SSDTBI,SNAC_SDK /Q /IACCEPTSQLSERVERLICENSETERMS
    

    which gives

    /ACTION=INSTALL

    /FEATURES=SSDTBI

    SNAC_SDK

    /Q

    /IACCEPTSQLSERVERLICENSETERMS

    To get rid of this problem you need to quote at least the FEATURES argument. I usually quote everything in those cases, just to be consistent, so

    & { $args } "/ACTION=INSTALL" "/FEATURES=SSDTBI,SNAC_SDK" "/Q" "/IACCEPTSQLSERVERLICENSETERMS"
    

    gives you the wanted parameters:

    /ACTION=INSTALL

    /FEATURES=SSDTBI,SNAC_SDK

    /Q

    /IACCEPTSQLSERVERLICENSETERMS

    Update: Many installers return immediately after they have been called while the install process still runs in the background, which can be a bugger when the rest of the script depends on the install.

    There are several methods to make powershell wait for a process exit. One of the shortest is to use Out-Null like this:

    & "\\mynetworkpath\SSDTBI_x86_ENU.exe" "/ACTION=INSTALL" "/FEATURES=SSDTBI,SNAC_SDK" "/Q" "/IACCEPTSQLSERVERLICENSETERMS" | Out-Null
    

    You may also want to look at $? or $LASTEXITCODE afterwards to check for errors.