Nikita Spitsky
Nikita Spitsky

Reputation: 79

How to add separator in powershell

please tell me, how to add separator in powershell?

I do out command:

Get-VM | Where-Object {$_.ExtensionData.Guest.ToolsStatus -notlike 'toolsOk'} | Select-Object Name, @{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}} | Format-Table -AutoSize

and get:

Name                          Tools Status
----                          ------------ 

Name1                         toolsOld 
Name2                toolsNotInstalled 
Name3                         toolsOld

but me need for format jira:

Name                          Tools Status
----                          ------------
|Name1                         |toolsOld|
|Name2                |toolsNotInstalled|
|Name3                         |toolsOld|

Can do it with help powershell?

Upvotes: 0

Views: 14496

Answers (1)

lit
lit

Reputation: 16236

If the goal is to produce a VERTICAL LINE delimited file, replace Format-Table with Export-Csv and set the -Delimiter parameter to a VERTICAL LINE.

Get-Process | Select-Object -Property Id,ProcessName | Export-Csv -Path ".\gp.csv" -Delimiter `| -NoTypeInformation

If you do not want each field to be quoted, they can be explicitly removed. Note that this removes -all- quotes. If the data contains quotes, a different method must be used.

Get-Process |
    Select-Object -Property Id,ProcessName |
    ConvertTo-Csv -Delimiter `| -NoTypeInformation |
    Select-Object {$_.Replace('"','')} |
    Out-File .\gp.csv

Alternatively, Out-GridView could be used to produce a GUI spreadsheet-like output.

UPDATE: for PowerShell 7.0+

Export-Csv has a -UseQuotes parameter which can be set to Never, Always, or AsNeeded. Use the command help Export-Csv for more information.

Upvotes: 3

Related Questions