Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Created December 23, 2015 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/1e9f3d8e8d885c3dfecc to your computer and use it in GitHub Desktop.
Save PlagueHO/1e9f3d8e8d885c3dfecc to your computer and use it in GitHub Desktop.
Example DSC Custom Exception
$errorId = 'iSCSIVirtualDiskRequiresRecreateError'
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument
$errorMessage = $($LocalizedData.iSCSIVirtualDiskRequiresRecreateError) -f $Path
$exception = New-Object -TypeName System.InvalidOperationException `
-ArgumentList $errorMessage
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
-ArgumentList $exception, $errorId, $errorCategory, $null
$PSCmdlet.ThrowTerminatingError($errorRecord)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment