Skip to content
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

Added some snippets #1297

Merged
merged 6 commits into from
Apr 30, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added max length of datatable
  • Loading branch information
SQLDBAWithABeard committed Apr 27, 2018
commit 9e52a26ff4f84cbdbbdf69ebd5859819a10e341a
26 changes: 26 additions & 0 deletions docs/community_snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _To contribute, check out our [guide here](#contributing)._
| [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ |
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ |
| [DataTable](#datatable): _Creates a DataTable_ |
| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets teh max length of string columns in datatables_ |

## Snippets

Expand Down Expand Up @@ -91,6 +92,31 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the
}
```

### MaxColumnLengthinDataTable

Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads into a SQL Server table with fixed column widths by @SQLDBAWithABeard

#### Snippet

```json
"Max Length of Datatable": {
"prefix": "Max Length of Datatable",
"body": [
"$$columns = ($$datatable | Get-Member -MemberType Property).Name",
"foreach($$column in $$Columns) {",
" $$max = 0",
" foreach ($$a in $$datatable){",
" if($$max -lt $$a.$$column.length){",
" $$max = $$a.$$column.length",
" }",
" }",
" Write-Output \"$$column max length is $$max\"",
"}"
],
"description": "Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads"
}
```

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