这个问题在没有完全理解.exe实际返回的内容时被问到。代码片段实际上返回了它应该的内容。
代码:
workflow parallelPrereqInstall{
param ($serverNames, $outputFile, $installFilePath)
Function Log-Write([string]$logString){
$logTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
$s = "$logTime $logString";
Add-Content $Using:outputFile -Value $s
Write-Host $logString
}
foreach -parallel($server in $serverNames){
$SPPrereqsInstalled = InlineScript {
$installSPPrereqs = {
$fullPath = "$args\prerequisiteinstaller.exe"
$prereqResult = Start-Process -FilePath $fullPath -ArgumentList "/unattended" -Verb RunAs -Wait -WindowStyle Maximized -PassThru
return $prereqResult.ExitCode
}
$user = "domain\admin"
$pass = "password"
$securePass = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $user, $securePass
Invoke-Command -ComputerName $Using:server -ScriptBlock $installSPPrereqs -ArgumentList $Using:installFilePath -Credential $cred -Authentication Credssp
}
}
我总是从-1
取回$prereqResults
,它似乎安装了一些东西,然后只是错误输出,而它应该再次运行和/或给我一个不同的退出代码。我不相信我得到了正确的退出代码。
如果我没有指定ExitCode属性,则prereqResults将返回如下:
@{Path=; Company=; CPU=0.0625; FileVersion=; ProductVersion=; Description=; Product=; __NounName=Process; PSComputerName=localhost; RunspaceId=a62e33ea-5f4c-4cae-85a4-d1426efacced; PSShowComputerName=True; PSSourceJobInstanceId=b2624e9f-5584-4874-a5b3-a9745f95bf42; ExitCode=-1; HasExited=True; ExitTime=03/20/2017 13:12:31; Handle=2504; SafeHandle=Microsoft.Win32.SafeHandles.SafeProcessHandle; Id=2980; MachineName=.; PrivilegedProcessorTime=00:00:00.0625000; StartInfo=System.Diagnostics.ProcessStartInfo; StartTime=03/20/2017 13:12:30; SynchronizingObject=; Total
ProcessorTime=00:00:00.0625000; UserProcessorTime=00:00:00; EnableRaisingEvents=False; Site=; Container=}
有人可以帮我弄清楚如何正确运行和退回退出代码吗?
答案 0 :(得分:0)
尝试Write-Output $ prereqResult并检查属性名称是否与“ExitCode”相同,也尝试Write-Output $ prereqResult.PSSourceJobInstanceId。
如果显示正确将其推送到变量并返回变量或使用select-string -pattern“ExitCode”
希望它有效