Enclose a list of strings in quotation marks using PowerShell

Enclose a list of strings in quotation marks using PowerShell

ยท

1 min read

Have you ever needed to enclose a long list of strings into quotation marks? I am in such a situation quite often. The last time it was when I was creating function Get-CMLog and I needed a list of available log names for the ValidateSet param check ๐Ÿ‘‡. image.png As you can see it would be super annoying to enclose it by hand. Moreover I got tired by creating code snippets like this (Get-Clipboard) -split "," | % {"'" + $_ + "'"} over and over again so I've decided to create small Quote-String function ๐Ÿ’ก.


What are the Quote-String function features

  • supports input from pipeline, parameter, and clipboard
  • splits given string(s) using a customizable delimiter, enclose the resulting items in the quote, and outputs the result into console or clipboard
    • result can be joined or outputted as an array

How to use it

  • Download, dot source and call it like ๐Ÿ‘‡ image.png
ย