PowerTip: Convert Character Array to String

Doctor Scripto

Summary: Easily convert a character array to a string in Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to convert data that is returning as an array of characters
          instead of as a single string?

Hey, Scripting Guy! Answer Use the unary operator, and pass the array. In the following example, the first command returns an
          array of characters, and the next the unary operator converts the character array to a single string:

PS C:\> $a = (get-module -l)[0].Path | split-path -Parent

PS C:\> $a[0]


PS C:\> $b = (,$a)

PS C:\> $b[0]


PS C:\>


Discussion is closed.

Feedback usabilla icon