Appending to pre-existing csv via Export-csv switch


how append csv file exists without overwriting initial data?  essentially, want write powershell code to append data an existing csv file or a building a new csv file without overwriting existing data when error encountered.  code below continues overwrite itself.

$credentials = get-credential domain\user_id
$servers = get-content .\servers.txt

foreach ($serveroccurrence in $servers)
{
   try{
   get-wmiobject -class win32_service -computername $serveroccurrence -credential $credentials -erroraction stop|where-object {$_.name -like "sym*"}|select-object -property __server, name, startmode, startname, state, pathname | export-csv drft11-28-2012-v.csv -notypeinformation
   }
   catch{
      write-host "couldn't contact server " $serveroccurrence -foregroundcolor green
      continue
   }
}

however, if run get-wmiobject command itself, seems works fine.  let  me know thoughts

get-wmiobject -class win32_service -computername (get-content .\servers.txt) -credential domain\user_id -erroraction stop|where-object {$_.name -like "sym*"}|select-object -property __server, name, startmode, startname, state, pathname | export-csv drft11-28-2012-v.csv -notypeinformation


i downloaded  powershell 3.0 , worked '-append' switch!!!

also, thank tip on writing object array well.

thank much.  input appreciated.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file