Unable to override the values of the configuration.ini file while doing SQL Install/Uninstall

  • HI Guys

    Please suggest how would I be able to override the values of $action, $features,$INSTANCENAME , etc....to pass the values in the below section to override the values of "install" by "uninstall" etc and run the program so that I can use the same .ini files for sql install/uninstall purposes or at a better choice I could be able to update the values dynamically to give argument to powershell to install sql with such parameter values

    please suggest how to write it

    $CONFIGURATIONFILE = "C:\test\Install_ConfigurationFile.ini"

    & $fileExe /CONFIGURATIONFILE=$CONFIGURATIONFILE

    clear-host

    $ini=get-content "C:\test\Install_ConfigurationFile.ini"

    $ini

    clear

    $ACTION = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'ACTION=*'}

    $FEATURES = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'FEATURES=*'}

    $INSTANCENAME = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'INSTANCENAME=*'}

    $INSTANCEID = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'INSTANCEID=*'}

    $SQLSYSADMINACCOUNTS = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'SQLSYSADMINACCOUNTS=*'}

    #Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'IAcceptSQLServerLicenseTerms=*'}

    $UpdateEnabled = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'UpdateEnabled=*'}

    $SQMREPORTING = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'SQMREPORTING=*'}

    $ERRORREPORTING = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'ERRORREPORTING=*'}

    $INDICATEPROGRESS = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'INDICATEPROGRESS=*'}

    $QUIET = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'QUIET=*'}

    $ACTION

    $FEATURES

    $INSTANCENAME

    $INSTANCEID

    $SQLSYSADMINACCOUNTS

    $UpdateEnabled

    $SQMREPORTING

    $ERRORREPORTING

    $INDICATEPROGRESS

    $QUIET

    $fileExe = "C:\SQL2012_X64_Copied\setup.exe";

    #$dir = Split-Path $fileExe

    try

    {

    $CONFIGURATIONFILE = "C:\test\Install_ConfigurationFile.ini"

    & $fileExe /CONFIGURATIONFILE=$CONFIGURATIONFILE

    echo INSTALLATION SUCCESSFULLY COMPLETED >> .\install_log.txt

    }

    catch {

    echo INSTALLATION ERROR (ERRORLEVEL=%ERRORLEVEL%) >> .\install_log.txt

    }

    Thanks.

  • It is probably me but I don't get it. Are you wondering how do use functions and parameters in a PowerShell script? Are you wanting an install function and an uninstall function that utilise the same values loaded from the same configuration file?

    I am happy to help once I know your issues.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Hi Gaz...Thanx for the response. YEs, I want an Install and Uninstall functions which can be easily be used to do SQL Server 2008/R2 and 2012 Install and Uninstall using .INI files.

    But in addition to that the complexity is, I want users to provide the below details while I run/call the functions as those details are important and will vary case to case!

    ACTION

    Features

    Instancename

    SQLSYSADMINACCOUNTS

    IAcceptSQLServerLicenseTerms

    UpdateEnabled

    INDICATEPROGRESS

    QUIET

    Also, if possible can save the results in an output files (other than summary.txt)

    I rewritten the module again and would appreciate a more fine tune to the below or a complete revamp for both SQL Install & Uninstall task.

    Let me know if I have able to explain clearly now. Thanks for your response. I truly appreciate

    clear

    $fileExe = "C:\SQL2012_X64_Copied\setup.exe";

    $setupDriveLetter = "C:\SQL2012_X64_Copied"

    #$dir = Split-Path $fileExe

    $SQLSVCPassword='Complex Pswd'

    $SQLAGENTPassword='Complex Pswd##'

    $SAPWD = 'Complex Pswd023'

    $CONFIGURATIONFILE = "C:\test\Install_ConfigurationFile.ini"

    try

    {

    $cmd = "$setupDriveLetter\Setup.exe /ConfigurationFile=$CONFIGURATIONFILE /SQLSVCPASSWORD=`'$SQLSVCPassword`' /AGTSVCPASSWORD=`'$SQLAGENTPassword`' /SAPWD=`'$SAPWD`'"

    $cmd

    Invoke-Expression -command $cmd

    echo INSTALLATION SUCCESSFULLY COMPLETED >> .\install_log.txt

    }

    catch {

    echo INSTALLATION ERROR (ERRORLEVEL=%ERRORLEVEL%) >> .\install_log.txt

    }

    Thanks.

  • Hi GAz

    Did you get a chance to look for my code?

    I modified it further but the two key values are not being passed proper thru function parameters. Plz suggest.

    Function InstallSQL ([string] $action,[string] $INSTANCENAME)

    {

    $fileExe = "C:\SQL2012_X64_Copied\setup.exe";

    $setupDriveLetter = "C:\SQL2012_X64_Copied"

    #$dir = Split-Path $fileExe

    $ACTION = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'ACTION=*'}

    $INSTANCENAME = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'INSTANCENAME=*'}

    $SQLSVCPassword=Pswd01

    #$INSTANCENAME = 'MSSQLServer'

    $SQLAGENTPassword='Pswd02'

    #$action = 'Install'

    $SAPWD = 'P2ssw0rd'

    $CONFIGURATIONFILE = "C:\test\Install_ConfigurationFile.ini"

    try

    {

    #& $fileExe /Q /CONFIGURATIONFILE=$CONFIGURATIONFILE | out-null;

    $cmd = "$setupDriveLetter\Setup.exe /ConfigurationFile=$CONFIGURATIONFILE /Action= $_$action /INSTANCENAME=`'$INSTANCENAME'` /FEATURES=`'SQLENGINE,SSMS'` /IACCEPTSQLSERVERLICENSETERMS=TRUE /SQLSVCPASSWORD=`'$SQLSVCPassword`' /AGTSVCPASSWORD=`'$SQLAGENTPassword`' /SAPWD=`'$SAPWD`'"

    $cmd

    #Invoke-Expression -command $cmd

    echo INSTALLATION SUCCESSFULLY COMPLETED >> .\install_log.txt

    }

    catch {

    echo INSTALLATION ERROR (ERRORLEVEL=%ERRORLEVEL%) >> .\install_log.txt

    }

    }

    #.\InstallSQL

    InstallSQL $action="Install" $INSTANCENAME= "INST2"

    Invoke-Expression -command $cmd

    Thanks.

  • I have now:

    function InstallSQL

    {

    [CmdletBinding()]

    Param

    (

    [Parameter(Position=0,Mandatory=$true)][string]$action

    ,[Parameter(Position=1,Mandatory=$true)][string]$INSTANCENAME

    )

    # Your code

    }

    #Calling the function:

    InstallSQL "Install" "INST2"

    That should do it.

    There are briefer ways to describe it but this is strict and should work.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Hello,

    Whenever I am running my script, getting the below error as in my conf.INI file I already has the value ACTION and INSTANCENAME.

    function InstallSQL

    {

    [CmdletBinding()]

    Param

    (

    [Parameter(Position=0,Mandatory=$true)][string]$action

    ,[Parameter(Position=1,Mandatory=$true)][string]$INSTANCENAME

    )

    $fileExe = "C:\SQL2012_X64_Copied\setup.exe";

    $setupDriveLetter = "C:\SQL2012_X64_Copied"

    #$dir = Split-Path $fileExe

    $ACTION = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'ACTION=*'}

    $INSTANCENAME = Get-Content "C:\test\Install_ConfigurationFile.ini" | Where-Object {$_ -like'INSTANCENAME=*'}

    $SQLSVCPassword='Pswd01'

    #$INSTANCENAME = 'MSSQLServer'

    $SQLAGENTPassword='Pswd02'

    #$action = 'Install'

    $SAPWD = 'P2ssw0rd'

    $CONFIGURATIONFILE = "C:\test\Install_ConfigurationFile.ini"

    try

    {

    #& $fileExe /Q /CONFIGURATIONFILE=$CONFIGURATIONFILE | out-null;

    $cmd = "$setupDriveLetter\Setup.exe /ConfigurationFile=$CONFIGURATIONFILE /Action= $_$action /INSTANCENAME=`'$INSTANCENAME'` /FEATURES=`'SQLENGINE,SSMS'` /IACCEPTSQLSERVERLICENSETERMS=TRUE /SQLSVCPASSWORD=`'$SQLSVCPassword`' /AGTSVCPASSWORD=`'$SQLAGENTPassword`' /SAPWD=`'$SAPWD`'"

    $cmd

    Invoke-Expression -command $cmd

    echo INSTALLATION SUCCESSFULLY COMPLETED >> .\install_log.txt

    }

    catch {

    echo INSTALLATION ERROR (ERRORLEVEL=%ERRORLEVEL%) >> .\install_log.txt

    }

    }

    #Calling the function:

    InstallSQL "Install" "INST3"

    C:\SQL2012_X64_Copied\Setup.exe /ConfigurationFile=C:\test\Install_ConfigurationFile.ini /Action= ACTION="Install" /INSTANCENAME='INSTANCENAME="INST3"' /FEATURES='SQLENGINE,SSMS' /IACCEPTSQLSERVERLICENSETERMS=TRUE /SQLSVCPASSWORD='Pswd01' /AGTSVCPASSWORD='P

    swd02' /SAPWD='P2ssw0rd'

    The following error occurred:

    The specified value for setting 'ACTION' is invalid. The expected values are:

    Thanks.

  • I would suggest renaming the parameters but you don't appear to be attempting to use them. Perhaps if you commented your code with your intentions then I could understand.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply