首页 > 解决方案 > 在 Powershell 中获取 Loadstate ExitCode ......我错过了什么?

问题描述

代码正在运行,但我无法将 Loadsate 中的退出代码提供给变量...我错过了什么?当我尝试输出 loadstate 退出代码时,它是空白变量。这是在 GUI 中使用的,一旦加载完成,我想做其他事情。

$USMTLoadState = Start-Process "$USMTDir\loadstate.exe" -ArgumentList $LoadStateArguments -PassThru -NoNewWindow
    $USMTLoadState
    
    # Give the process time to start before checking for its existence
    Start-Sleep -Seconds 3
                
        # Wait until the save state is complete
        try
        {
            $LoadProcess = Get-Process -Name loadstate -ErrorAction Stop
            while (-not $LoadProcess.HasExited)
            {
                Get-USMTProgress -ActionType 'Load'
                Start-Sleep -Seconds 30
            }
            
            Update-Log 'Results:'
        Get-USMTResults -ActionType 'Load'
        
        # Sometimes loadstate will kill the explorer task and it needs to be start again manually
        if (-not (Get-Process -Name explorer -ErrorAction SilentlyContinue))
        {
            Update-Log 'Restarting Explorer process.'
            Start-Process explorer
        }
        $USMTExitCode = $USMTLoadState.ExitCode
        Update-Log "Finished with ExitCode: $USMTExitCode" -Color 'Black'
        Write-log -Path $USMTRestoreLog -Message "Finished with ExitCode: $USMTExitCode" -Component "Script" -Type Info
        if ($USMTExitCode -eq 0)
        {
            Update-Log "Complete!" -Color 'Green'
            
            # Delete the save state data
            try
            {
                Get-ChildItem "$MigrationStore\$OldComputer" | Remove-Item -Recurse
                Update-Log 'Successfully removed old save state data.'
            }
            catch
            {
                Update-Log 'There was an issue when trying to remove old save state data.'
            }
        }
        else
        {
            update-log 'There was an issue during the loadstate process, please review the results. The state data was not deleted.'
        }

标签: powershellusmt

解决方案


推荐阅读