Skip to content

Commit c79f559

Browse files
omniomiTylerLeonhardt
authored andcommitted
Add parameter-credential snippet. (#1295)
Adding a snippet for the creation of a -Credential parameter within functions.
1 parent 3580fe9 commit c79f559

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/community_snippets.md

Lines changed: 22 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
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ |
2020
| [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ |
21+
| [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ |
2122

2223
## Snippets
2324

@@ -58,6 +59,27 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the
5859
}
5960
```
6061

62+
### Parameter-Credential
63+
64+
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
65+
66+
#### Snippet
67+
68+
```json
69+
"Parameter-Credential": {
70+
"prefix": "parameter-credential",
71+
"body": [
72+
"# Specifies the user account credentials to use when performing this task.\r",
73+
"[Parameter()]\r",
74+
"[ValidateNotNull()]\r",
75+
"[System.Management.Automation.PSCredential]\r",
76+
"[System.Management.Automation.Credential()]\r",
77+
"$$Credential${1: = [System.Management.Automation.PSCredential]::Empty}"
78+
],
79+
"description": "Parameter declaration snippet for a Credential parameter."
80+
}
81+
```
82+
6183
## Contributing
6284

6385
If you'd like to add a snippet to this list, [open a pull request](https://opensource.guide/how-to-contribute/#opening-a-pull-request) with the following changes:

0 commit comments

Comments
 (0)