0

How to edits the questions is like to be ask by someone

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for your help :)
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.