I have below script ...
param (
[Parameter(Mandatory)]
[String] $Path,
[decimal] $days
)
$text = get-content $path
(Get-Content $path).Replace("`t", " ") | set-content "C:\anil\input555.txt"
$path = "c:\anil\input555.txt"
$ErrorActionPreference = 'Stop'
$count=0
$data = Get-Content $path
$limit = (Get-Date).AddDays(-$days)
#$data[0] -replace ' +',"`t" # replace space with tab in first line
$data | Select-Object | % {
$null = $_ -match '^(/data/.+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+)'
$timestamp = [DateTimeOffset]::FromUnixTimeMilliseconds($Matches[2]/1000000).DateTime
if ($timestamp -lt $limit) {
$formattedTimestamp = Get-Date $timestamp -Format 'yyyy-MM-dd' $Matches[1],$formattedTimestamp,$Matches[3],$Matches[4],$Matches[5],$Matches[6],$Matches[7],$Matches[8],$Matches[9] -join "`t"
$count++
}
}
write-host "Number of Matches for more than $days days older: $count files"
Here i want total size in GB by adding all $Matches[4] WHERE they suffice "$timestamp -lt $limit". Another thing so $Matches[4] has value in bytes.
my output looks like
Number of Matches for more than 100 days older: 20000 files with toatal size xxxxxGB
param (
[Parameter(Mandatory)]
[String] $Path,
[decimal] $days
)
$text = get-content $path
(Get-Content $path).Replace("`t", " ") | set-content "C:\anil\input555.txt"
$path = "c:\anil\input555.txt"
$ErrorActionPreference = 'Stop'
$count=0
$data = Get-Content $path
$limit = (Get-Date).AddDays(-$days)
#$data[0] -replace ' +',"`t" # replace space with tab in first line
$data | Select-Object | % {
$null = $_ -match '^(/data/.+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+)'
$timestamp = [DateTimeOffset]::FromUnixTimeMilliseconds($Matches[2]/1000000).DateTime
if ($timestamp -lt $limit) {
$formattedTimestamp = Get-Date $timestamp -Format 'yyyy-MM-dd' $Matches[1],$formattedTimestamp,$Matches[3],$Matches[4],$Matches[5],$Matches[6],$Matches[7],$Matches[8],$Matches[9] -join "`t"
$count++
}
}
write-host "Number of Matches for more than $days days older: $count files"
Here i want total size in GB by adding all $Matches[4] WHERE they suffice "$timestamp -lt $limit". Another thing so $Matches[4] has value in bytes.
my output looks like
Number of Matches for more than 100 days older: 20000 files with toatal size xxxxxGB