Skip to content

Add parameter-credential snippet. #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/community_snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _To contribute, check out our [guide here](#contributing)._
|:-----------------:|
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ |
| [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ |
| [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ |

## Snippets

Expand Down Expand Up @@ -58,6 +59,27 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the
}
```

### Parameter-Credential

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

#### Snippet

```json
"Parameter-Credential": {
"prefix": "parameter-credential",
"body": [
"# Specifies the user account credentials to use when performing this task.\r",
"[Parameter()]\r",
"[ValidateNotNull()]\r",
"[System.Management.Automation.PSCredential]\r",
"[System.Management.Automation.Credential()]\r",
"$$Credential${1: = [System.Management.Automation.PSCredential]::Empty}"
],
"description": "Parameter declaration snippet for a Credential parameter."
}
```

## Contributing

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:
Expand Down