Do you need to convert an array of elements into a single string in PowerShell? In this PowerShell tutorial, I will explain how to convert an array to a string in PowerShell. We’ll explore several methods to convert an array to a string in PowerShell, with complete examples.
To convert an array to a string in PowerShell, you can use the -join operator to concatenate the array elements with a specified delimiter. For example, $string = $array -join ‘, ‘ will create a string from the array $array, with each element separated by a comma and a space. Alternatively, you can pipe the array to Out-String for a simple conversion without delimiters.
Convert an Array to a String in PowerShell
An array is a data structure that holds multiple items, which can be of various types, including strings, integers, and even other arrays. In PowerShell, arrays are defined using the @() syntax, and elements within an array are separated by commas.
For example:
$array = @(1, 2, 'three', 'four')Let’s look at different ways to convert this array into a string in PowerShell.
Method 1: Using the -join Operator
The -join operator is one of the simplest ways to convert an array to a string in PowerShell. It concatenates each array element into a single string, with the option to add a delimiter between elements.
Example:
$array = @(1, 2, 'three', 'four')
$string = $array -join ', '
Write-Output $stringOutput:
1, 2, three, fourIn this example, we used a comma followed by a space as the delimiter, but you can use any string or character as the delimiter, or even an empty string if you don’t want any separator.
You can see the output in the screenshot below after I executed the PowerShell script.

Method 2: Using Out-String Cmdlet
The Out-String the cmdlet in PowerShell is another way to convert an array to a string. It’s particularly useful when you want to convert the array’s default output to a string format.
Example:
$array = @(1, 2, 'three', 'four')
$string = $array | Out-String
Write-Output $string.Trim()The Trim() method in PowerShell is used here to remove any extra whitespace from the beginning and end of the string, which can be a common occurrence when using Out-String.
Look at the screenshot below. This is the output after I executed the PowerShell script above using VS code.

Method 3: Using .NET’s String.Join Method
PowerShell is built on .NET, so you can leverage .NET classes and their methods. One such method is String.Join, which is similar to the -join operator but is a static method of the String class.
Example:
$array = @(1, 2, 'three', 'four')
$string = [System.String]::Join(", ", $array)
Write-Output $stringThis method is particularly powerful because it provides the flexibility of .NET’s string manipulation capabilities.
Method 4: Using Type Casting
You can also convert an array to a string by casting the array as a string type in PowerShell. This method is known as explicit type conversion or casting.
Example:
$array = @(1, 2, 'three', 'four')
$string = [string]$array
Write-Output $stringThis will convert the array into a string with space as the default delimiter between elements in PowerShell.
Here is the output; look at the screenshot below:

This is another way to convert an array to a string in PowerShell.
Method 5: Using ForEach-Object and += Operator
You can iterate through each element of the array and append it to a string variable using the += operator in PowerShell. This method provides more control over the conversion process.
Example:
$array = @(1, 2, 'three', 'four')
$string = ''
$array | ForEach-Object { $string += "$_ " }
Write-Output $string.Trim()This script concatenates each element of the array to the $string variable with a space in between. The Trim() method is used at the end to remove the trailing space in PowerShell.
join an array of strings in PowerShell
Here, I will show you one example of “PowerShell join array of strings”.
To join an array of strings in PowerShell, you can use the -join operator. Here is an example:
# Define an array of strings
$arrayOfStrings = @("Hello", "world", "from", "PowerShell")
# Join the array into a single string with spaces as the delimiter
$joinedString = $arrayOfStrings -join " "
# Output the result
Write-Output $joinedStringThis will output:
Hello world from PowerShellYou can see the output in the screenshot below after I executed the above PowerShell using Visual Studio code.

PowerShell: array to string with delimiter
To convert an array to a string with a specified delimiter in PowerShell, you can use the -join operator. Here is a detailed example:
- Define an Array: First, create an array of strings.
- Join the Array: Use the
-joinoperator with the desired delimiter.
# Define an array of strings
$arrayOfStrings = @("apple", "banana", "cherry")
# Join the array into a single string with commas as the delimiter
$joinedString = $arrayOfStrings -join ", "
# Output the result
Write-Output $joinedStringHere is an explanation of the above PowerShell script.
- Array Definition: The array
$arrayOfStringscontains three elements:"apple","banana", and"cherry". - Join Operation: The
-joinoperator is used to concatenate the elements of the array into a single string, with each element separated by a comma and a space (", "). - Output: The
Write-Outputcmdlet prints the resulting string.
The output of the above script will be:
apple, banana, cherryYou can also see in the screenshot below:

Conclusion
Converting an array to a string in PowerShell is possible by using different ways like by using built-in cmdlets like Out-String, operators like -join, .NET methods like String.Join, or even a simple loop with ForEach-Object, etc.
In this PowerShell tutorial, I have explained how to convert an array to a string in PowerShell using various methods. You also know how to convert an array to a string using a delimiter in PowerShell.
You may also like:
- How to Export an Array to CSV in PowerShell?
- How to Create an Empty Array in PowerShell?
- How to Split Strings into Arrays in PowerShell?
- How to Check if a String Exists in an Array in PowerShell?
- How to Remove Blank Lines from an Array in PowerShell?
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.