Author Posts

April 27, 2016 at 8:27 am

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.

April 27, 2016 at 8:41 am

try this line instead

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

April 27, 2016 at 9:17 am

That did it. However it mashed them together like

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

April 27, 2016 at 9:59 am

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

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