CSV file logging need help RRS feed

  • Question

  • Hi,

    I am working on a logging script for some servers, the data im looking to pull is all users logged on, date, count. i want to run this for about 3 days and pull data about 5 mins apart.

    I am outputting to a csv file, but when it outputs its overwriting my previous data. I tried noclobber but that just errors out and says file already exists

    $date = Get-Date -format g
    $server = "ctx45dcepc62"
    $file = ".\users.csv"
    Import-Module psterminalservices
    $users = get-tssession -computername $server -Filter {$_.username -AND $_.ConnectionState -eq 'Active'} | select username
    $count = $users.Count
    $users | add-member -name Date -type noteproperty $date
    $users | add-member -name Count -type noteproperty $count
    $users | export-csv $file -NoTypeInformation

    Could some one help me out, or should i not use export-csv? Also how would i get a 5 min timer to run this script say for 3 days?

    Thanks in advance

    • Edited by ImMax Tuesday, August 21, 2012 2:19 PM
    Tuesday, August 21, 2012 2:18 PM


  • $users | ConvertTo-Csv -NoTypeInformation | select -Skip 1 | Add-Content rec.csv
    • Proposed as answer by Bigteddy Tuesday, August 21, 2012 2:43 PM
    • Marked as answer by Yan Li_ Monday, August 27, 2012 9:11 AM
    Tuesday, August 21, 2012 2:22 PM