macxcoolParticipantJuly 25, 2016 at 12:55 pmPost count: 23
I want to check to see if a vhdx is still mounted and unmount it if there’s an error in the install script. I thought I could just put code in the ‘Catch’ section at the end of the ‘Deploy-Applications.ps1’ script. Apparently not.
Is there anything I can do to make that work?
That_annoying_guyParticipantJuly 25, 2016 at 7:55 pmPost count: 42
Test-VHD is probably your best bet https://technet.microsoft.com/en-us/library/hh848580.aspx
I suspect you need to add -ErrorAction ‘Stop’ to ensure you get a terminal error to get ‘Catch’ to work.
macxcoolParticipantJuly 25, 2016 at 9:20 pmPost count: 23
I’m not trying to test anything with the vhd, I’m just trying to get some code to run if the script crashes for some reason. I can figure out what to do with the vhd etc.
I think -ErrorAction ‘Stop’ is the default for the Deploy-Application.ps1 script anyway. It does error out when something catestrophic happens.
How do I add code to run when the script exits suddenly?
That_annoying_guyParticipantJuly 27, 2016 at 3:13 pmPost count: 42
Then your original idea should work UNLESS the error happens before Resolve-Error is declared.
If that is the case, look at the code I proposed in issue 163
macxcoolParticipantJuly 27, 2016 at 3:22 pmPost count: 23
All I’m doing (I’m sorry, the vhdx was a bit of a red herring) is using
Execute-Processwith a non-existent executable to trigger the fail. Then I want to insert some code that runs when the fail happens.
I’d be happy if
Write-Host 'Something bad just happened'ran 😉 I can fill in the rest later.
- This reply was modified 1 year, 7 months ago by macxcool.
macxcoolParticipantJuly 27, 2016 at 9:11 pmPost count: 23
I’m just placing something like
Execute-Process -Path 'C:\temp\something.exe'in the Installation section of the script. It’s not very important except that I’m forcing an error to occur, something.exe doesn’t exist.
Then I put some code in the Catch at the end of the script thinking that it would execute when the function failed.
That_annoying_guyParticipantJuly 28, 2016 at 4:18 pmPost count: 42
I tried and got this:
<code>... [07-28-2016 12:11:36.410] [Initialization] [Execute-Process] :: [C:\temp\something.exe] is a valid fully qualified path, continue. [07-28-2016 12:11:36.445] [Initialization] [Execute-Process] :: Function failed, setting exit code to . Error Record: ------------- Message : File [C:\temp\something.exe] not found. InnerException : FullyQualifiedErrorId : File [C:\temp\something.exe] not found. ScriptStackTrace : at Execute-Process<Process>, C:\<path>\PSADT_v3.6.9_Beta\AppDeployToolkit\AppDeployToolkitMain.ps1: line 2766 at <ScriptBlock>, C:\Users\UserName\AppData\Local\Temp\e3523fab-7a02-476f-8eee-0f3ddae37418.ps1: line 2 at <ScriptBlock>, <No file>: line 1 PositionMessage : At C:\<path>\PSADT_v3.6.9_Beta\AppDeployToolkit\AppDeployToolkitMain.ps1:2766 char:6 + Throw "File [$Path] not found." + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [07-28-2016 12:11:36.460] [Initialization] [Exit-Script] :: Deploy-Application_v1r1 Installation completed with exit code . [07-28-2016 12:11:36.475] [Initialization] [Test-PowerPoint] :: Check if PowerPoint is in either fullscreen slideshow mode or presentation mode... [07-28-2016 12:11:36.486] [Initialization] [Test-PowerPoint] :: PowerPoint application is not running. [07-28-2016 12:11:36.493] [Initialization] [Test-PowerPoint] :: PowerPoint is running in fullscreen mode [False]. [07-28-2016 12:11:36.504] [Initialization] [Show-BalloonTip] :: Display balloon tip notification with message [Installation failed.]. ...</code>
Try to give it a REAL file to look at. Make it a 0 byte file.
You must be logged in to reply to this topic.