You can dump directly to SQL, I do that for gathering stats for our VM admins. I don't like looking at csvs or text files anymore than the next DBA.
Once you have a list of counters (note I have some extra properties in my object collection) - you could simply call a proc (or just directly insert them)
$CounterCollection | Where-Object{$_.Path -ne $null} | ForEach-Object{
$qry = "EXEC .dbo.pr_Add_Perf_Collection "
$qry = $qry + " @server='" + [string]$_.Server + "'"
$qry = $qry + ", @performance_metric='" + [string]$_.Path + "'"
$qry = $qry + ", @performance_value=" + [decimal]$_.CookedValue
$qry = $qry + ", @date_sampled='"+ $_.Timestamp + "'"
$qry = $qry + ", @samples_taken=" + $_.Samples
$qry = $qry + ", @sample_interval=" + [int]$_.SampleInterval
Invoke-SqlNonQuery -ServerInstance $SQLServerToStore -Query $qry
}
function Invoke-SqlNonQuery{
param(
[string]$ServerInstance,
[string]$Query
)
$QueryTimeout=30
$conn=new-object System.Data.SqlClient.SQLConnection
$constring = "Server=" + $ServerInstance + ";Integrated Security=True"
$conn.ConnectionString=$constring
$conn.Open()
if($conn){
$cmd=new-object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$cmd.ExecuteNonQuery() | out-null
$conn.Close()
}
}
Hope this helps. I will see about writing a perfmon metric gather/storage article if SSC wants to publish it.
Cheers
http://twitter.com/widba
http://widba.blogspot.com/