Skip to main content

Enclose a list of strings in quotation marks using PowerShell

Published 1 min readMarkdown
Part of seriesOther stuff
Enclose a list of strings in quotation marks using PowerShell

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

About the author

  • I work as System Administrator for more than 15 years now and I love to make my life easier by automating work & personal stuff via PowerShell (even silly things like food recipes list generation).

No comments yet. Be the first to comment.

More from this blog