Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Exporting perfmon (get-counter) values to a SQL database

$
0
0

Hi,

I would like to capture some performance counters from a few Exchange servers and write them to a SQL 2008 R2 database.

I found a powershell script on the internet that can do this (it 's partly shown below):

------------------------------------------

$Metrics = Get-Counter -ComputerName $Server -Counter $Counters -SampleInterval 1 -MaxSamples 1  
# Open SQL Connection

$SQLConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=$sqlserver;Initial Catalog=$db;User Id=$UserID;Password=$Password;")

$SQLConn.Open()

$Sequence = 1

foreach($metric in $metrics)           
    {           
     
   $Obj = $Metric.CounterSamples | Select-Object -Property Path, CookedValue, Timestamp;   
   $Obj | Add-Member -MemberType NoteProperty -Name Computer -Value $Server   -Force;
   $Obj | Add-Member -MemberType NoteProperty -Name Sequence -Value $Sequence -Force;                      
      
   $Obj | Export-Csv $Server-Sysperf.csv -NoTypeInformation;            
   $Sequence += 1;           
   
   $SQLCmd = $SQLConn.CreateCommand()   

   
   $SQLCmd.CommandText = "INSERT INTO $tblname (ServerName, Path, CookedValue, Timestamp, Sequence )
   VALUES  ('$Server','Path','CookedValue', 'Timestamp','$Sequence')"
     
   $SQLCmd.ExecuteNonQuery()   
 }

------------------------------------------

It writes everything nicely in the csv-file.

But in the SQL tablet I only get the $Server and $Sequence value.

How do I get the other values (Path, CookedValue, Timestamp) in the SQL table?


Viewing all articles
Browse latest Browse all 8428

Trending Articles