Return only specific content of a file

This topic contains 2 replies, has 2 voices, and was last updated by  Jency 2 years, 2 months ago.

  • Author
    Posts
  • #26842

    Jency
    Participant

    Hi guys, I am now working with FSRM quotas and we would like to send emails to all users that are exceeding their defined soft quotas. I know there is an option to do this automatically within FSRM, but the requirement to send an email to users on regular basis until they move data somewhere else.

    I set up a CSV report to run daily and here is the output:

    "Quota Usage Report"

    Generated at: "24/06/2015 10:20:06 a.m."

    "Lists the quotas that exceed a certain disk space usage level. Use this report to quickly identify quotas that may soon be exceeded so that you can take the appropriate action."

    Report settings:
    Machine: ,"server1"
    Report Folders: ,"D:\users",
    Parameters: ,"Minimum Quota used percent: 0%"

    Report Totals
    Files shown in the report
    Quotas,Quota Usage
    "3","735 MB"
    All files matching report criteria
    Quotas,Quota Usage
    "3","735 MB"

    Report statistics
    Folder,Owner,Quota,Usage,Percent Used(%),Peak Usage,Peak Usage Time
    "D:\users\folder1","Contoso\user1","150 MB","406 MB","270.40" %,"406 MB","13/11/2014 1:29:37 p.m."
    "D:\users\folder2","Contoso\user2","150 MB","213 MB","142.19" %,"618 MB","13/11/2014 1:29:38 p.m."

    Etc.

    Is there an easy way in powershell to return only the part after "Report statistics"?

    I though about select-string with context parameter, but I don't know how many additional lines can be in the report. There might be few more lines above it for other servers. I also thought about regex check, but I am not that familiar with regex yet and the data in the lines I am interested in are also shown earlier in the output (e.g. date, path), so I am not sure if this can be used anyhow.

    I might be able to figure the issue out with using a loop through the content. But I believe there might be something way easier (most likely a one-liner?) to get the same result.

    Thank you.

  • #26848

    GJ
    Participant

    You can select the line number of the search line "Report statistics" and use it as a reference to all the lines below to it. Assuming you have have only online with "Report statistics" and all the lines below to it are of CSV, below may help.

    
    (Get-Content .\fsrm.txt)[((Get-Content .\fsrm.txt | Select-String -Pattern "^Report statistics$").LineNumber),-1] | ConvertFrom-Csv 
    
    
    
    PS [14:55:35] C:\POSH> Get-Content .\fsrm.txt
    "Quota Usage Report"
    
    Generated at: "24/06/2015 10:20:06 a.m."
    
    "Lists the quotas that exceed a certain disk space usage level. Use this report to quickly identify quotas that may soon be exceeded so that you can take the appropriate action."
    
    Report settings:
    Machine: ,"server1"
    Report Folders: ,"D:\users",
    Parameters: ,"Minimum Quota used percent: 0%"
    
    Report Totals
    Files shown in the report
    Quotas,Quota Usage
    "3","735 MB"
    All files matching report criteria
    Quotas,Quota Usage
    "3","735 MB"
    
    Report statistics
    Folder,Owner,Quota,Usage,Percent Used(%),Peak Usage,Peak Usage Time
    "D:\users\folder1","Contoso\user1","150 MB","406 MB","270.40" %,"406 MB","13/11/2014 1:29:37 p.m."
    "D:\users\folder2","Contoso\user2","150 MB","213 MB","142.19" %,"618 MB","13/11/2014 1:29:38 p.m."
    
    PS [14:55:36] C:\POSH> (Get-Content .\fsrm.txt)[((Get-Content .\fsrm.txt | Select-String -Pattern "^Report statistics$").LineNumber),-1] | ConvertFrom-Csv | ft -AutoSize
    
    Folder           Owner         Quota  Usage  Percent Used(%) Peak Usage Peak Usage Time        
    ------           -----         -----  -----  --------------- ---------- ---------------        
    D:\users\folder2 Contoso\user2 150 MB 213 MB 142.19 %        618 MB     13/11/2014 1:29:38 p.m.
    
    
    
    
  • #26902

    Jency
    Participant

    Thank you very much GJ.
    In the end I found a way how to filter ":\" string with regex, and skip the first occurrence. But I am not entirely sure how many times it may appear in the report before the statistics. It works for the example, but may not work for the real data.
    You solution is more efficient, I didn't realize I can do it this way. I am pretty sure the "Report statistics" caption will be there just once.
    Just a quick note – there is no need to pipe it together, select-string already supports -Path parameter.

You must be logged in to reply to this topic.