Created
October 22, 2014 18:52
-
-
Save trondhindenes/33c012e046e74ee8b40a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Workflow NonTerminatingFail1 | |
{ | |
new-item -ItemType file -Path "Z:\snakkes.txt" | |
Write-Output "The script continued" | |
} | |
Workflow TerminatingFail1 | |
{ | |
Param ($FirstNumber,$SecondNUmber) | |
$result = $FirstNumber / $SecondNUmber | |
$result | |
Write-Output "This never gets printed" | |
} | |
Workflow ErrorHadlingScript1 | |
{ | |
Param ([int]$FirstNumber,[int]$SecondNUmber) | |
Try | |
{ | |
$result = $FirstNumber / $SecondNUmber | |
} | |
Catch | |
{ | |
$err = $_ | |
} | |
if ($err) | |
{ | |
Write-output "We got an error. Stopping the runbook" | |
Return | |
} | |
$result | |
Write-Output "This gets printed if the workflow succeeded" | |
} | |
WOrkflow ParentCallingChildFail | |
{ | |
NonTerminatingFail1 | |
} | |
WOrkflow ParentCallingChildFail2 | |
{ | |
try | |
{ | |
NonTerminatingFail1 | |
} | |
Catch | |
{ | |
$err = $_ | |
} | |
if ($err) | |
{ | |
Write-output "We got an error. Stopping the runbook" | |
Return | |
} | |
} | |
WOrkflow ParentCallingChildGoodStuff1 | |
{ | |
try | |
{ | |
NonTerminatingFail1 -ErrorAction Stop | |
} | |
Catch | |
{ | |
$err = $_ | |
} | |
if ($err) | |
{ | |
Write-output "We got an error. Stopping the runbook" | |
Return | |
} | |
} | |
WOrkflow InlineScriptChattyNess | |
{ | |
$result = InlineScript { | |
new-item "C:\temp\testfile.txt" -Force -ItemType file | |
$result = Get-content "C:\temp\testfile.txt" | |
$result | |
} | |
Write-Output $result | |
} | |
WOrkflow InlineScriptChattyNess2 | |
{ | |
$result = InlineScript { | |
new-item "C:\temp\testfile.txt" -Force -ItemType file | out-null | |
Set-content -Path "C:\temp\testfile.txt" -Value "Hallais" | |
$result = Get-content "C:\temp\testfile.txt" -Force | |
$result | |
} | |
Write-Output $result | |
} | |
Workflow InlineScriptErrorHandling | |
{ | |
$errorCollection = New-Object -Type System.Management.Automation.PSDataCollection[System.Management.Automation.ErrorRecord] | |
InlineScript { | |
Try | |
{ | |
new-item "Z:\temp\testfile.txt" -Force -ItemType file | out-null | |
} | |
Catch | |
{ | |
write-error $error[0] | |
} | |
} -PSError $errorcollection | |
if ($errorCollection.count -gt 0) | |
{ | |
Write-Output "Error in the workflow - stopping" | |
return | |
} | |
#Continue with the next step | |
} | |
workflow InlineScriptErrorHandlingwitherrorOutput | |
{ | |
$errorCollection = New-Object -Type System.Management.Automation.PSDataCollection[System.Management.Automation.ErrorRecord] | |
InlineScript { | |
Try | |
{ | |
new-item "Z:\temp\testfile.txt" -Force -ItemType file | out-null | |
} | |
Catch | |
{ | |
write-error $error[0] | |
} | |
} -PSError $errorcollection | |
if ($errorCollection.count -gt 0) | |
{ | |
Write-Output "Error in the workflow - stopping. Here are the error(s):" | |
foreach ($err in $errorCollection) | |
{ | |
Write-Output "$($err.Exception.Message)" | |
} | |
} | |
#Continue with the next step | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment