Remote SQL Installation

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of ##Nick ##Nick 1 year, 8 months ago.

  • Author
    Posts
  • #25111
    Profile photo of ##Nick
    ##Nick
    Participant

    I've been trying for several hours to get the proper script to run an installation file remotely.
    I'm on my machine, location and target of install is $targetmachine.

    First, I copy the installation files locally. Works fine.
    Second, I setup my session. Works fine.

    $session = New-PSSession -ComputerName $targetmachine
    

    Finally, I attempt to perform the installation. The first part simply tests the registry key presence.
    The second part (else) is where I'm running into trouble. I cannot understand why the setup.exe file is not firing.
    I've tried many variations and haven't been able to have the install start.

    $sqlversion = '2012-dev-x64'

    Invoke-Command -Session $session {param($sqlversion)      
            if (Test-Path -path 'hklm:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQLServer\CurrentVersion\') 
                {
                    Write-Host "`n SQL Server is already installed, exiting script." -BackgroundColor "Yellow" -ForegroundColor "Black"
                }
            Else
                {
                    Write-Host "SQL Server not found, beginning installation"
                    Write-Host "Installation Start Time:"
                    $a = Get-Date
                        "Date: " + $a.ToShortDateString()
                        "Time: " + $a.ToShortTimeString()
                   Invoke-Command {Start-Process "c:\_installs\$sqlversion\setup.exe" -ArgumentList "/ConfigurationFile=c:\_installs\$sqlversion\configurationfile.ini"}
                }
                } -ArgumentList $sqlversion
    }
    

    I truly appreciate the assistance.

    PS. I've tried these also;
    Other Attempt
    $setup = Invoke-Expression -Command "c:\_installs\$sqlversion\setup.exe" -ArgumentList '/ConfigurationFile=c:\_installs\$sqlversion\configurationfile.ini"

    Other Attempt
    $setup = Start-Process "c:\_installs\$sqlversion\setup.exe" -ArgumentList "/ConfigurationFile=c:\_installs\$sqlversion\configurationfile.ini" -Wait
    if ($setup.exitcode -eq 0)
    {
    Write-Host "`nSQL Server Installation Completed at:" -BackgroundColor "Yellow" -ForegroundColor "Black"
    $a = Get-Date
    "Date: " + $a.ToShortDateString()
    "Time: " + $a.ToShortTimeString()

  • #25116
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Hey Nick,

    First thing I'd do in your script is change the Write-Host's to Write-Output's. That way you can get the output stream data displayed on your console. I'd maybe also write out the value of your variables to ensure they are set correctly.

    Might be more worthwhile though looking into using DSC. There's a DSC resource for installing and configuring SQL available, which you can get from the latest DSC resource kit.

  • #25117
    Profile photo of Lauras Juozulynas
    Lauras Juozulynas
    Participant

    Hi Nick,

    Try adding "$sqlversion" in second Invoke-Command argument list (inside script) .

    Or:

    Also it looks like you are invoking command inside already started invoke-command. Try running only

    Start-Process "c:\_installs\$sqlversion\setup.exe" -ArgumentList "/ConfigurationFile=c:\_installs\$sqlversion\configurationfile.ini"

    Instead of Invoke-command.

    • #25173
      Profile photo of ##Nick
      ##Nick
      Participant

      Laurus,

      I appreciate your response. I wasn't sure whether the Invoke-Command would persist through the entire script block.
      Sometimes I write the words and realize how ridiculous it sounds for me to have thought that way originally :).

      So, having run your recommended script, I no longer get an error (bonus). However, the script appears to end without running the start-process.
      It goes from my Installation Start Time including the Date and Time and then hits the Start-Process, pauses for a few seconds, then back to PS prompt.

      Write-Host "Installation Start Time:"
                      $a = Get-Date
                          "Date: " + $a.ToShortDateString()
                          "Time: " + $a.ToShortTimeString()
                      
                      Start-Process "c:\_installs\$using:sqlversion\setup.exe" -ArgumentList "/ConfigurationFile=c:\_installs\$using:sqlversion\configurationfile.ini" -Verbose
      

      I'm beginning to wonder whether its a permission issue though I'm an administrator in both locations (single-sign-on).
      Thoughts?

You must be logged in to reply to this topic.