我正在尝试使用PowerShell DSC安装HPC Pack 2012 R2 U3设置。以下代码可以并安装软件:
$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
然而,当我使用脚本DSC配置运行相同的东西时,它成功但返回非常快,退出代码为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
这是Package
资源使用的相同代码,该代码失败,因为返回错误代码10而不是0(当程序包安装成功时就是这种情况,就像在最顶层的代码示例中一样)。安装程序不会生成任何输出或日志文件。
有什么想法吗?我很难过。
答案 0 :(得分:1)
我发现了问题。我认为这与权限有关,因为设置在正常运行时提供了UAC提升提示。但是,之前我把它划掉了两个原因:
Package
资源的本地管理员凭据(这不起作用):
Package InstallHpcHeadNode
{
Ensure = "Present"
Name = $HpcPackName
ProductId = ""
Path = $HpcPackSourcePath
Arguments = $Arguments
Credential = (Get-Credential)
}
但这是一个错误。来自docs的Credential属性说:
提供对远程源上的包的访问。这个属性是 不习惯安装包。
我承认我忽略了。我应该使用PsDscRunAsCredential
属性来强制使用提供的凭据进行安装。仍然不知道为什么安装程序不能在NT AUTHORITY \ SYSTEM下运行。