Moose
Moose

Reputation: 755

Adding new lines to Existing CSV using powershell?

I wrote a script that would fetch all the services running under an account name. This part works fine except I want to add results to an existing csv. Add-content is messing up with my format. Please help as i am new here.

script:

$servers = @("a", "b")
$domain = "abc.com"

foreach($server in $servers){

$serverFQDN = $server+"."+"$domain"
    Invoke-Command -computername $serverFQDN{
        param($server)
        Write-host "On" + $server -ForegroundColor Yellow
        Get-WMIObject Win32_Service | Where-Object {$_.startname -match "ciqdev*" }
        # | where-object {$_.state -eq "running"}           
    }-argumentlist $server | select pscomputername,caption | export-Csv Z:\RT\myCSV.csv

}

Upvotes: 1

Views: 2996

Answers (1)

Manu
Manu

Reputation: 1742

Use -Append :

export-Csv Z:\RT\myCSV.csv -Append

Upvotes: 3

Related Questions