$sfn = Import-Csv -Path 'C:\Apptier\Docs\Test.csv'
$sfn2 = $sfn|?{$.SrcArrivalDate -ne '1970-01-01'} | select 'Time','FileName'
$a = $sfn2 | Group-Object Time | Select-Object count, Name, @{ n='Size' ; e={ ($.Group | Measure-Object 'FileName').Count}}
foreach($q in $a)
{
$k = $q.Name -replace ".{3}$"
if($k -eq (Get-Date -Format "HH:mm"))
{
"name=Custom Metrics|Test|Rows|"+$($k)+"|Count,value="+"$(([int]$q.Size))"
}
}
Note: There are four row values under Time Column
23:59:42
23:59:16
23:59:51
23:59:53
name=Custom Metrics|Test|Rows|23:59|Count,value=1
name=Custom Metrics|Test|Rows|23:59|Count,value=1
name=Custom Metrics|Test|Rows|23:59|Count,value=1
name=Custom Metrics|Test|Rows|23:59|Count,value=1
name=Custom Metrics|Test|Rows|23:59|Count,value=4
Thanks for the above workaround, it worked.
Need another help on to fetch the values on Hourly and Minutes basis.
For Hourly, I can get the results using below Script 1.
But when trying to get the values for Hour and Minutes there is an issue that I'm unable to remove the Seconds from 'TIME' header.
This is because, my script runs for every minute and want to fetch the values for every minute after comparing the Date and Time with System Date and Time.
So Please help me in removing the Seconds from TIME header and fetch the values after comparing the Hours and Minutes with System Hours and Minutes.
Even written a Script 2 for this , but there is an issue in the script.
Issue here is, multiple outputs were printed as there are different seconds for same Hour and Mins.
$sfn = Import-Csv -Path 'C:\Apptier\Docs\Test.csv'
$sfn2 = $sfn|?{$.Date -ne '1970-01-01'} | select 'Hour','FileSize(KB)'
$a = $sfn2 | Group-Object Hour | Select-Object count, Name, @{ n='Size' ; e={ ($.Group | Measure-Object 'FileSize(KB)' -Sum).Sum}}
foreach($q in $a)
{
if($q.Name -eq (Get-Date -Format "HH"))
{
"name=Custom Metrics|Test|Rows|"+$($q.Name)+"|Count,value="+"$(([int]$q.Size))"
}
}
Hi,
I see an error after executing the script. But the result for the $clean is showing.
You cannot call a method on a null-valued expression.
At line:22 char:1
+ [PSCustomObject]@{
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull