Output Data from several CSV cells into String

This topic contains 3 replies, has 3 voices, and was last updated by  Don Jones 2 years ago.

  • Author
  • #38309

    Long S

    I am pulling information from a csv. I want to input this data into a Word Document on separate lines.
    My csv is something like:
    8533, A10 Networks
    8533, Active Directory
    8533, Video Teleconference (VTC)
    8533, Remote Access Policy
    8236, Microsoft Outlook 2010

    My code look like:

    $key = Read-Host "Please enter Key"
    $csv = Import-CSV "file.csv"

    [string]$key = $key
    $csv | where {$_.VKEY -eq $key } |Foreach{
    [string]$stigs = $_.STIGS -join '`n'

    SearchAWord –Document $Doc -findtext 'STIG ' -replacewithtext $stigs

    This only inputs the first cell from the csv into the word document. Im assuming something needs to go next to [string]$stigs = $_.STIGS. I tried `n, `r, -join.

  • #38310

    Anthony Stringer

    try this line instead

    $stigs = ($csv | where {$_.VKEY -eq $key }).STIGS -join "`n"
  • #38311

    Long S

    That did it. However it mashed them together like

    A10 Networks Active Directory Video Teleconference (VTC) Remote Access Policy Microsoft Outlook 2010

  • #38312

    Don Jones

    You might also try piping your result to Out-String –

    $csv | where { whatever } | Select stigs | Out-String

You must be logged in to reply to this topic.