Output Data from several CSV cells into String

Tagged: ,

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Don Jones Don Jones 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38309
    Profile photo of Long S
    Long S
    Participant

    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:
    KEY, STIGS
    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
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    try this line instead

    $stigs = ($csv | where {$_.VKEY -eq $key }).STIGS -join "`n"
    
    #38311
    Profile photo of Long S
    Long S
    Participant

    That did it. However it mashed them together like

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

    #38312
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.