VMware Cloud Community
msaxbury
Enthusiast
Enthusiast

PowerShell software component fails despite $LASTEXITCODE = 0

Error at end of software component configure action:

ABORT. Encountered error in Powershell.
Error while executing script: Process exited with an error: 1 (Exit value: 1)

Software and versions:

-vRA Version: 7.5.0 (Build: 10053500)

-vSphere Client version 6.7.0.20000

-VM is Windows 2016 Datacenter - Win32NT 10.0.14393.0 Microsoft Windows NT 10.0.14393.0

-chef-solo:

     chef_version=13.2.20

     ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]

-SQL Server 2016 Enterprise Core

-SSMS 2016 Enterprise Core

Configurations:

-VMware Guest Agent is installed with software bootstrap on the VM template, downloaded from IaaS server, so it is version 7.5.0.

-"VMware vRealize.....Bootstrap" Windows Service is running under a custom service account that is configured in the admin group for the server.

-Blueprint consists of 1 vSphere machine and contains 1 software component with powershell code in the install and configure action, no reboot specified.

    Install action checks for existence of shared NAS drive (server with file sharing turned on, XServe) and creates PS-drive object.

    Configure action copies files from the share to the E:\ drive of the VM, expands packages to E:\ and C:\, and then executes a chef cookbook that was copied to the c:\chef\cookbooks folder.

-Chef sql cookbook does NOT perform a reboot after sql is installed.

-software component configure action does have the reboot check box checked.

Process Flow:

The following is my Try/Catch block, which executes successfully manually running under the same service account the "VMware vRealize.....Bootstrap" Windows Service runs under, on any VM provisioned from the template.

It also completes successfully when executed under the vRA software components. SQL is installed, configured, and works successfully.

However, vRA reports exit code 1?

#Execute the DBinstaller to run DBConfigurationScripts

Try{

    cd $dbcExpandLoc

    $curDir = PWD

    Write-Output "LastExitCode BEFORE = $($LASTEXITCODE)"

    If($curDir.Path -eq $dbcExpandLoc.Remove($dbcExpandLoc.Length - 1)){

        $dbcExecute = E:\00.Install\CareSource.Core.Tools.DatabaseInstaller\DatabaseInstaller.exe deploy -v d -m $dbcExpandLoc$manifestFile -s $server$dbInstance

        Write-Output "LastExitCode AFTER = $($LASTEXITCODE)"

        $success = $dbcExecute -match "Changed database"

If($dbcExecute){

            Write-Output "Success: database script completed."

            Write-Output "LastExitCode END = $($LASTEXITCODE)"

            exit 0

            $LASTEXITCODE = 0

        }

    } Else {

        $errorMsg = "Could not change directories to DatabaseInstaller directory."

        Write-Output $errorMsg

        exit -1

    }

} Catch [Exception] {

    $errorMsg = $_.Exception

    Write-Output $errorMsg

}

exit 0

$LASTEXITCODE = 0

Write-Output "LastExitCode FINAL = $($LASTEXITCODE)"

Here is the output from the vRA provision, there is no other error above, it executes ALL software component configure action powershell code successfully.

pastedImage_12.png

The sql service gets installed on the VM successfully:

pastedImage_19.png

3 seconds later there is a WMI warning event gets created:

pastedImage_18.png

The Microsoft WMI provider note explains why it records this warning, the sql server installer is spawning a provider in a separate host process running under LocalSystem, which is a security risk triggering the warning.

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd...

This "slightly" answered thread does not apply - vRA Software Components script error  because I am leaving the SQL port as default. The sql service is being installed and configured to run under the same service account as the "VMware vRealize.....Bootstrap" Windows Service. SQL is successfully installed and works fine. However, I read a similar thread that I can't find that indicated that WMI will throw an exit code for the warning.

I removed the software components and provisioned a brand new VM, then ran the software components code manually, to see if during the chef solo install of SQL, the WMI event would be created. It was created. I believe the WMI error is somehow bubbling up to vRA as exit code 1 for the script but cannot seem to capture it from the software component code.

0 Kudos
5 Replies
daphnissov
Immortal
Immortal

See, LucD​, THIS is why I was talking about vRA software agent running PowerShell and understanding what it's doing Smiley Happy

I feel your pain and I've had to deal with this several times. Short of identifying where exactly this is catching an error, something I've had to use in the past (because I couldn't figure it out) is to use the $errors.clear() method in .NET to reset that back to 0. This is only safe to do if you're doing error handling in another way (like parsing an output file). Regarding the specifics of WMI error codes, that might be caught with a Start-Transcript before your script. Luc may also have some other creative ideas.

0 Kudos
LucD
Leadership
Leadership

When you start an EXE in a PowerShell you can't really blame PowerShell for not reporting the EXE's exit code or return code.

And no, I'm afraid I don't have a one-size-fits-all solution for this issue.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
msaxbury
Enthusiast
Enthusiast

LucD​, daphnissov

IF I set the reboot flag in the sql answer file(chef cookbook attribute), the error does NOT occur and the provision is successful. All other code still reports no error.

The issue is not that the EXE does not report back the code to powershell, but that vRA does not capture the failure somewhere to let you know. Hence, the ask by LucD to understand more in depth what is happening.

**HOW does sql installer, or chef or whoever is throwing a warning or error, report the error back to vRA so that it thinks the powershell session failed, when ALL items from Powershell are valid and correct for no failure. There is a protocal or channel that vRA is monitoring that tells it some message occured and to "kind of" fail the deploy but not notify Powershell. WHERE IS THAT, HOW DOES THAT HAPPEN?

0 Kudos
daphnissov
Immortal
Immortal

I believe this was covered in another thread. In this case, the exit code indicates a reboot is needed, not that a failure occurred. The error makes it way back to vRA in the form of a wrapper script which actually calls the software component, but, this is the part that's frustrating, it seems only that wrapper script catches this exit/error and not the actual software component script.

0 Kudos
msaxbury
Enthusiast
Enthusiast

daphnissov

When I run the chef cookbook to install SQL Server manually on any server, I do not get any kind of reboot notice. The Chef cookbook attribute file contains a reboot = false attribute. I can run the cookbook successfully with the /QS flag which shows me a SQL gui as it progresses and no reboot indicator is prompted.

A msdn post indicated that chef was failing because SQL Server installation was returning exit code 3010 which indicates reboot.

SQL Server 2016 unattended setup reboot required 3010

The installation log for SQL indicates 0 as the exit code for the provision in vRA that is "partially" successful. Where is the exit code non zero coming from that vRA receives in the wrapper script that executes the software components?

pastedImage_0.png

pastedImage_1.png

pastedImage_2.png

0 Kudos