HTML report for File Share info - against several servers?

This topic contains 3 replies, has 2 voices, and was last updated by  Don Jones 3 years, 8 months ago.

  • Author
    Posts
  • #14013

    Jake Sully
    Participant

    Hello,

    I continue learning a great deal on here, I am trying to create a report I thought would be easier. But I'm getting stuck trying to figure out how to write a report that would:

    A. Gather the quotas setup on file servers that run Windows 2003 and 2008R2

    B. Provide an HTML or Excel report with the data. Given it's multiple servers, I'm thinking excel might be better, perhaps 1 sheet per server?

    C. Email the sheet when a scheduled task runs weekly.

    I've been working on this for a little while now and can't seem to get to where I need at all, which is frustrating. I know the command I need to run is: dirquota quota list

    I think I need to start with a foreach loop that will accept either 1 server name or get-content where I put in the path of a text file with the server names. Then store the properties I need in an array or variable? After that I think it's exporting the data to excel, and ideally the "sheet" in excel would be named the name of the server, and then the email portion would come in last?

    Then I need these properties:

    Quota Path: D:\Share\Marketing
    Source Template: 300 MB Limit (Does not match template)
    Quota Status: Enabled
    Limit: 50.00 MB (Hard)
    Used: 1.00 KB (0%)
    Available: 50.00 MB

    If anyone can help it would be great!

  • #14016

    Don Jones
    Keymaster

    Have you considered looking at powershell.org/wp/ebooks, where we have a free book on creating HTML reports? I don't believe Excel is a good reporting tool, personally, but HTML can work well. Excel is also a pain to automate from within PowerShell (in my opinion), whereas HTML is very easy to produce. The free ebook has a number of examples, and you can start very simple and work up to quite complex formatting and display.

  • #14018

    Jake Sully
    Participant

    Thanks Don! I have that Ebook and I'm trying to get this working. I also bought your last book series and dvds but it's trying to learn while working as I've never been a programmer/scripter. of course trying to learn while meeting the requests that are non-stop makes it harder as I'm going through the materials on my time and learning the right way, in the meantime I'm using the online resources to try to get these things done.

    Right now I'm stuck on just running the for-each loop for the command. Then when I get that working I'm not sure how to convert it to the html format, and finally email it.

    If I can do the for-each loop, then how would you handle sending out a report if it's for multiple file servers? Or should I just create the script and schedule it to run against a single server as a scheduled task, then schedule it to run for all of the others? That doesn't seem right, but otherwise the html report would be quite long as it's for 10 servers and many quotas are enabled per server.

    How would you handle it?
    I read a post about creating HTML reports here:
    http://thesurlyadmin.com/author/martinpugh/

    The part I get stuck on is how to get the data into the format, then send the email. I can figure out the loop I think, but it's the rest that I get lost on.

    Thanks as always,
    Jake

  • #14019

    Don Jones
    Keymaster

    In pseudo code, assuming $computers contained one or more computer names, I'd so something like this:

    foreach ($computer in $computers) {
    # make up a filename based on the computer name
    # retrieve whatever information from the computer
    # produce the HTML report for the computer
    }

    In terms of "getting the data in the format," you have to get the data into an object. The HTML book offers several examples. I usually do this by writing a short function:


    Get-Data {
    param($computername)
    $rawdata = Get-Something -Computername $computername
    $raw2 = Get-SomethingElse -Computername $computername
    $properties = @{'ComputerName'=$computername;
    'OneThing'=$rawdata.someproperty;
    'Another'=$raw2.anotherproperty}
    New-Object -Type PSObject -Prop $properties
    }

    That combines information from two commands into a single output object. You then convert that to an HTML fragment:


    foreach ($computer in $computers) {
    $filename = "report-$($computer).html"
    $frag1 = Get-Data -Computername $computer | ConvertTo-HTML -Fragment -As Table -Pre "

    Data 1

    " | Out-String
    $frag2 = Get-OtherData -Computername $computer | ConvertTo-HTML -Fragment -As List -Pre "

    More Info

    " | Out-String
    ConvertTo-HTML -Title "For $computer" -Body "

    Report for $computer

    ",$frag1,$frag2 | Out-File $filename
    }

You must be logged in to reply to this topic.