format list of items with double quotes

Kylek12 1 Reputation point
2022-10-25T23:48:57.01+00:00

Hello,

I'm trying to use -join to add "" to each item in a list and separate those items with a comma. I'm having trouble adding the quotes to the start of the first item and at the end of the last item in the list. Any help would be appreciated.

format list with "",""

$migratableInfra.id -join """, """

****missing quote here****80028575-0419-4606-b4d6-9fe92cb5fddc", "9d3ebc0f-d417-4ca2-a2f8-77e8bf176741", "76558545-cf6b-4f2a-8d0c-ddf111318317", "61527f1f-648b-4d27-84b1-dddc8882aa01", "727c776b-0cdd-4e82-a445-13fb5aa59f9e", "3d7bf58f-9620-4903-a6b8-1cf25d21bcf4", "0e84d8c7-b73f-4ec4-b893-4ca489704b2e", "5b49b6f6-805c-41b1-8933-5217cbc81320", "b4cf2c5a-fcc0-405e-b5af-e6686800ccfe", "c2003f91-9698-4aec-9eeb-8e82eaabf6f6", "5b7386d2-f751-48ef-bcdd-67af3fa48a3f", "b6930200-c11b-4026-a021-a1ed81488cde", "952dab4f-7c9d-44b6-b434-090f45fde209****missing quote here****

Thanks,

Kyle

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,378 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 31,581 Reputation points
    2022-10-26T00:59:44.28+00:00

    Is this what you want?

    ""  
    $array = @('aaaa','bbbb','cccc')  
    "Starting array..."  
    $array  
    ""  
    $string = '"{0}"' -f ($array  -join """, """)  
    "As a string..."   
    $string  
    
    0 comments No comments