powershelldscpowershell-dsc

Installing an exe with PowerShell DSC returns exit code only when run through LCM


I am trying to install the HPC Pack 2012 R2 U3 setup using PowerShell DSC. The following code works and installs the software:

    $HpcPackName = "Microsoft HPC Pack 2012 R2 Server Components"
    $HpcPackSourcePath = "C:\Temp\HPC2012R2_Update3_Full\setup.exe"
    $sqlServer = "EMEAWINQA15"
    $Arguments = "-unattend -headNode"

    function InstallUsingProcess
    {
        [CmdletBinding()]
        param()

        Write-Verbose "HpcPackSourcePath: $HpcPackSourcePath"
        Write-Verbose "Arguments: $Arguments"

        $startInfo = New-Object System.Diagnostics.ProcessStartInfo
        $startInfo.FileName = $HpcPackSourcePath
        $startInfo.Arguments = $Arguments

        $process = New-Object System.Diagnostics.Process
        $process.StartInfo = $startInfo

        $exitcode = 0
        $process.Start() | Out-Null

        $process.WaitForExit()

        if($process)
        {
            $exitCode = $process.ExitCode
            Write-Verbose "Exit code: $exitCode"
        }
    }

    InstallUsingProcess -Verbose

However, when I run the same thing using a Script DSC configuration, it succeeds but returns very quickly with exit code 10:

Configuration TestHpcInstall
{
    Import-DscResource –ModuleName PSDesiredStateConfiguration

    Node $AllNodes.Where({$_.Roles -contains 'HpcHeadNode'}).NodeName
    {
        $HpcPackName = "Microsoft HPC Pack 2012 R2 Server Components"
        $HpcPackSourcePath = "C:\Temp\HPC2012R2_Update3_Full\setup.exe"
        $sqlServer = "EMEAWINQA15"
        $Arguments = "-unattend -headNode"

        Script TestInstall
        {
            GetScript = {
                return @{ "Result" = "$true"}
            }
            TestScript = {
                return $false
            }
            SetScript = {
                Write-Verbose "HpcPackSourcePath: $using:HpcPackSourcePath"
                Write-Verbose "Arguments: $using:Arguments"

                $startInfo = New-Object System.Diagnostics.ProcessStartInfo
                $startInfo.FileName = $using:HpcPackSourcePath
                $startInfo.Arguments = $using:Arguments

                $process = New-Object System.Diagnostics.Process
                $process.StartInfo = $startInfo

                $exitcode = 0
                $process.Start() | Out-Null

                $process.WaitForExit()

                if($process)
                {
                   $exitCode = $process.ExitCode
                   Write-Verbose "Exit code: $exitCode"
                }
            }
        }
    }
}

TestHpcInstall -ConfigurationData $configData -OutputPath "C:\Temp"
Start-DscConfiguration -ComputerName "EMEAWINQA15" -Path "C:\Temp\" -Verbose -Wait -Force

This is the same code used by the Package resource, which fails because error code 10 is returned instead of 0 (which is the case when the package installs successfully, as in the top-most code sample). The setup does not produce any output or log file.

Any ideas? I'm stumped.


Solution

  • I found the problem. I thought this had something to do with permissions because the setup gives a UAC elevation prompt when run normally. However, I had crossed it out before for two reasons:

    1. LCM runs under NT AUTHORITY\SYSTEM account and is therefore an administrator, and
    2. Because I supplied local administrator credentials to the Package resource already like so

    (which didn't work):

    Package InstallHpcHeadNode
    {
        Ensure = "Present"
        Name = $HpcPackName
        ProductId = ""
        Path = $HpcPackSourcePath
        Arguments = $Arguments
        Credential = (Get-Credential)
    }
    

    But this was a mistake. From the docs, the Credential property says:

    Provides access to the package on a remote source. This property is not used to install the package.

    which I'll admit I overlooked. I should have instead used the PsDscRunAsCredential property to force the installation using the supplied credentials. Still don't know why the installer doesn't run under NT AUTHORITY\SYSTEM though.