How to edits the questions is like to be ask by someone
2 Answers
You can use Export-Csv for this.
First, you'll want to create objects rather than strings from the two arrays:
$objects = foreach($f1 in $file1)
{
foreach($f2 in $file2)
{
New-Object psobject -Property @{
Server = $f1
HotfixID = $f2
}
}
}
Now we can pipe these to Export-Csv and specify a delimiter (a space in your case):
$objects |Export-Csv -Path "C:\path\to\output.file" -Delimiter ' ' -NoTypeInformation
1 Comment
Atul D
Thank you so much for your help :)
You've fallen into the same trap as many others when working with PowerShell - you're manipulating text instead of objects.
Instead of concatenating strings ({$f1+","+$f2}), create an object:
{ New-Object PSObject -Property @{ "Server" = $f1; "Hotfix" = $f2 } }
Then, wrap the whole ForEach in parentheses, and assign to a variable:
$hfdata = ( ForEach ... )
...and finally, Export-CSV the array:
Export-CSV -InputObject $hfdata -Path $savefile