Hi
I’m trying to take some disk stats/info from csv files with Import-Csv and then use the Save-ReportData from the SQLReporting module in “Creating Historical and Trend Reports with PowerShell and SQL Server” to store the data in a MSSQL database.
I’ve attached a sample of how the csv file looks. And here is the code I have as a starting point just to see if I can get it to work:
$Path = "M:\Scripts\Reports\mdisk.csv"
$CSV = Import-Csv -Path $Path -Header "Collected", "MDisk", "ReadIOPS", "WriteIOPS", "ReadBlocks", "WriteBlocks",
"ReadExternalResponseTime", "ReadQueuedResponseTime",
"WriteExternalResponseTime", "WriteQueuedResponseTime",
"PeakReadExternalResponseTime", "PeakReadQueuedResponseTime",
"PeakWriteExternalResponseTime", "PeakWriteQueuedResponseTime"
#$CSV = $CSV | select -Skip 1
$properties = @{'Collected'=$CSV.Collected;
'MDisk'=$CSV.MDsik;
'ReadIOPS'=$CSV.ReadIops;
'WriteIOPS'=$CSV.WriteIOPS;
'ReadBlocks'=$CSV.ReadBlocks;
'WriteBlocks'=$CSV.WriteBlocks;
'ReadExternalResponseTime'=$CSV.ReadExternalResponseTime;
'ReadQueuedResponseTime'=$CSV.ReadQueuedResponseTime;
'WriteExternalResponseTime'=$CSV.WriteExternalResponseTime;
'WriteQueuedResponseTime'=$CSV.WriteQueuedResponseTime;
'PeakReadExternalResponseTime'=$CSV.PeakReadExternalResponseTime;
'PeakReadQueuedResponseTime'=$CSV.PeakReadQueuedResponseTime;
'PeakWriteExternalResponseTime'=$CSV.PeakWriteExternalResponseTime;
'PeakWriteQueuedResponseTime'=$CSV.PeakWriteQueuedResponseTime}
$obj = New-Object -TypeName PSObject -Property $properties
$obj.PSObject.TypeNames.Insert(0,'Report.MDiskInfo')
Write-Output $obj
This is the error message I’m getting at this point:
"Exception calling “ExecuteNonQuery” with “0” argument(s): “String or binary data would be truncated.
The statement has been terminated.”
At C:\Users\xyz\Documents\WindowsPowerShell\Modules\SQLReporting\SQLReporting.psm1:64 char:13
-
$cmd.ExecuteNonQuery() -
~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : NotSpecified: (
, MethodInvocationException - FullyQualifiedErrorId : SqlException"
- CategoryInfo : NotSpecified: (
I’ve tried to manually edit the headers in the csv file to the names I have in the code above, I have tried to only have one column in the csv file was well but I get the same error. So I’m obviously missing and doing this wrong. I’ve tried with full SQL 2012 SP2 server and a local SQL Express.
I’ve run the Collect-DiskSpaceInfo.ps1 that’s included in the ebook, and that works well. And from the verbose output I think that at least a part of the problem is that the it’s trying to put for example all of the timestamp/collected values into the same value/row. I’m not sure what to try or how to proceed with this, any help, tips or guidance is appreciated.