I’m familiar with the Line Continuation in PowerShell feature for keeping code from running far out of view.
Is there a way to use this method - or similar - to work with a long string variable? When I tried this, it would output the string as multiple lines instead of a single line.
I’m adding headers to a CSV file before I populate it with some metadata and file property values. I currently have 21 headers (for now), and so using a single variable, they run way off screen in the script editor. I wanted to see if there was a way to show them on multiple lines within the script, but only write them to the CSV file on a single line.
Here’s what my current string variable looks like:
$TemplateHeaders = "FileName,FileSize,Duration,Audio Count,Text Count,Title,Format,v BitRate,BitDepth,Standard,v StreamSize,a Language,a CodecID,a Duration,a BitRate,Channel(s),a StreamSize,t CodecID,t Duration,t StreamSize,t Language,"
These fall into four categories, and I wanted to work with them in the script on their own lines so it’s more readable.
I just tried the following to achieve the desired results, but was wondering if there is a more professional way:
Here I have each category seperated into their own strings:
$gHeader = "FileName,FileSize,Duration,Audio Count,Text Count,Title,Format" $vHeader = "v BitRate,BitDepth,Standard,v StreamSize" $aHeader = "a Language,a CodecID,a Duration,a BitRate,Channel(s),a StreamSize" $tHeader = "t CodecID,t Duration,t StreamSize,t Language"
Having it displayed on multiple lines makes it easier to manage the headers (add, remove, etc.)
Here I’m combining them into a single string:
$TemplateHeaders = "$gHeader,$vHeader,$aHeader,$tHeader,"
Here I just write the column headers to a new (empty) csv file:
Add-Content -Path $OutFile -Value $TemplateHeaders
Is there a way to achieve the same single line output results, but work with the data in the script across multiple lines?