1

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

}

1 Answer 1

3

Use -Append :

export-Csv Z:\RT\myCSV.csv -Append
Sign up to request clarification or add additional context in comments.

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.