Skip to content

Commit daba6b7

Browse files
authored
Update community_snippets.md
1 parent c7336de commit daba6b7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/community_snippets.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ _To contribute, check out our [guide here](#contributing)._
1818
|:------------------|
1919
| [CalculatedProperty](#calculatedproperty): _Create a calculated property for use in a select-object call by @corbob_ |
2020
| [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ |
21+
| [Error-Terminating](#error-terminating): _Create a full terminating error by @omniomi_ |
2122
| [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ |
2223
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ |
2324

@@ -55,6 +56,26 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the
5556
}
5657
```
5758

59+
### Error-Terminating
60+
61+
Quickly add a fully defined error record and throw. by @omniomi
62+
63+
#### Snippet
64+
65+
```json
66+
"Throw Terminating Error": {
67+
"prefix": "error-terminating",
68+
"body": [
69+
"\\$Exception = New-Object ${1:System.ArgumentException} (\"${2:Invalid argument provided.}\")\r",
70+
"\\$ErrorCategory = [System.Management.Automation.ErrorCategory]::${3:InvalidArgument}\r",
71+
"# Exception, ErrorId as [string], Category, and TargetObject (e.g. the parameter that was invalid)\r",
72+
"\\$ErrorRecord = New-Object System.Management.Automation.ErrorRecord(\\$Exception, '${4:InvalidArgument}', \\$ErrorCategory, ${5:\\$null})\r",
73+
"\\$PSCmdlet.ThrowTerminatingError(\\$ErrorRecord)"
74+
],
75+
"description": "Throw a full terminating error."
76+
}
77+
```
78+
5879
### Parameter-Credential
5980

6081
Add a `-Credential` parameter that supports a PSCredential object in a variable, `-Credential (Get-Credential)`, or `-Credential Username` (will prompt). Includes an empty PSCredential object as the default value but this is the first tabstop so pressing backspace after inserting the snippet removes it. by @omniomi

0 commit comments

Comments
 (0)