Thank you for your help LucD!
Your script got me what I wanted.
Now all I have to do is gather the files.
As you mentioned the script you offered gives me 1 csv file per 1 resource pool a day.
When I have collected 1 month of data, I would want to organize this into 1 monthly csv file per 1 resource pool.
To do that I was thinking of the following.
$rpname = "rp1"
$folder = "C:\powercli\stats"
dir C:\powercli\stats *$rpname* | Import-Csv |
Where-Object {$_."Resource Pool" -match "$rpname"}|
Sort-Object "Interval Start" -Descending |
Export-Csv -Path $folder\$rpname.csv -NoTypeInformation
The script above imports all the csv files that has the name rp1 and then exports it again with the resource pool name for the file name, Which is good.
However I would have to make a script for each resource pool and execute them over and over.
I wanted to know if it was possible to loop this script for multiple resource pools (e.g. rp1, rp2, rp3, rp4......)
I assumed I would use the "foreach-object" cmdlet but I am not sure how to.
Thank you in advance.