Powershell script and system shutdown when task is complete


Author
Message
RayG
RayG
Advanced Member
Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)Advanced Member (489 reputation)
Group: Forum Members
Posts: 241, Visits: 1.1K
I have a powershell script that modifies the backup XML to set the shutdown options if the script is passed the appropriate parameter. However when the script execute the shutdown appears to be fully implemented in reflect.exe and that means that the script never gets to finish the post backup processing this is the section of code in the powershell script and if a shutdown/hibernate/suspend is indicated then we never get to the "write-host 'done' line of code.

Is it possible for macrium to spawn off a subprocess with a user modifiable timeout such that any script can complete before the shutdown event happens.

function Backup()
{
  $strType = GetBackupTypeParameter;
  $strArgs = "-e -w $strType `"$strXmlFilePath`"";
  Write-Host " * Running the backup... $StrType" ($GlobalTonguearameters -replace "`"`"", "" -replace "$strType", "") -NoNewLine;
  write-debug "(Start-Process -FilePath $strReflectPath -ArgumentList $strArgs -PassThru -Wait).ExitCode;"
  $iResult = (Start-Process -FilePath $strReflectPath -ArgumentList $strArgs -PassThru -Wait).ExitCode;
  Write-Host 'Done.';
  switch ($iResult)
  {
    2 { OnXmlValidationError; break; }
    1 { OnBackupError;        break; }
    0 { OnBackupSuccess;      break; }
  }
  return $iResult;
}

I appreciate that there may be other ways to circumvent the problem but I though I would ask this here first.



Regards
RayG
Windows10 X64 V1803 B17134.48 MR v7.1.3196

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search