Skip to content

Instantly share code, notes, and snippets.

@fatherjack
Created February 28, 2022 11:39
Show Gist options
  • Save fatherjack/94e4414f3f0af7a658edae2c75d17865 to your computer and use it in GitHub Desktop.
Save fatherjack/94e4414f3f0af7a658edae2c75d17865 to your computer and use it in GitHub Desktop.
Creates a quoted, comma separated list of values
function New-QuotedString {
<#
.SYNOPSIS
Takes a pasted set of cells from Excel and returns a quoted, comma separated string that can be pasted into SSMS for a SQL filter
.DESCRIPTION
Long description
.PARAMETER ItemsList
The cell list from Excel as a string - just paste inside a pair of quotes and assign that to a variable
.EXAMPLE
$x = "Books
Cheese and biscuits
Humous"
$x | New-QuotedString
result:
'Books','Cheese and biscuits','Humous'
.NOTES
Author: @fatherjack
Date: 20220228
#>
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true)]
[string]
$ItemsList
)
process {
"'{0}'" -f ($ItemsList -replace ("`r`n", "','"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment