Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Morning Report Revised

Posted on February 13, 2012

Last month I posted a PowerShell script I called The Morning Report. I received some very nice feedback. One comment was about making it easier to use the script in a pipelined expression. For example, get a list of computers from a text file and create a single HTML report. That sounds reasonable to me so I decided to revisit the script and add a few tweaks.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The latest version can still be used as I originally described. But now the computername parameter can be piped in to the script.


PS C:\> $report=get-content computers.txt | c:\scripts\morningreport.ps1

The report will still write a collection of custom report objects to the pipeline. But now I can do this:


PS C:\> get-content computers.txt | c:\scripts\morningreport.ps1 -text | out-file c:\work\morning-report.txt

This will create a single text file for all computers in the list. If you prefer a separate file per computer, use a ForEach loop.


PS C:\> get-content computers.txt | foreach {
>> $comp=$_
>> c:\scripts\morningreport.ps1 -Comp $comp -text |
>> out-file "c:\work\$comp-morning-report.txt"
>> }
>>

Similarly, I can now create a single HTML file.


PS C:\> get-content computers.txt | c:\scripts\morningreport.ps1 -html -hours 36 | out-file c:\work\morning-report.htm

I had to revise the HTML related code a bit to accommodate multiple computers in the same file. I modified the navigation links to the computername and inserted a list of computers at the beginning of the file. Clicking on a computername will take you to the corresponding summary. I probably wouldn't try this with hundreds of computers, but for most small to mid-size groups I think this will work just fine.

The last change I made, which was as much for me as anyone, was to add a -Quick parameter. Querying event logs is time consuming so if you are in a hurry you can skip the event log query by using -Quick. You'll still get an event log section in the output, but it will be empty.

Download the revised version of MorningReport.ps1 and let me know what you think.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

26 thoughts on “Morning Report Revised”

  1. Pingback: The PowerShell Morning Report | The Lonely Administrator
  2. Jeffery Hicks says:
    February 14, 2012 at 8:16 am

    I made a slight change after posting this to set the $OK variable to $False in the process loop. As it was originally, if I piped in a list of computers where the first was was online but the second one wasn’t, the $OK variable was still set to True. The takeaway here is to always define variables with a value. Don’t just assume they exist. Bad on me. The most current script version is 1.1.6.

  3. Eric Iverson says:
    March 23, 2012 at 4:46 pm

    Great script. I was looking for something to list out the running services with the stare authority and came accross this. Only problem I have had with it is on a Windows 2000 OS I can’t seem to get the Network stuff. Thanks

    1. Jeffery Hicks says:
      March 23, 2012 at 4:52 pm

      That wouldn’t surprise me. New classes and properties are added to WMI it seems with every OS release. There’s nothing you can do. Most likely what the report is querying can’t be retrieved from WMI on Windows 2000. I don’t even think I have a Windows 2000 box anywhere to even test in. Thanks for sharing your experience.

      1. Eric Iverson says:
        March 26, 2012 at 11:34 am

        That is what I figured. Tks

  4. Eric Iverson says:
    March 26, 2012 at 11:33 am

    I am trying to run the Morning Report as a scheduled task. Does not seem to work.
    Created a batch file that I call from the Scheduled task called MorningReportD.bat
    Contents:
    powershell -command “& ‘get-content InPutServers.txt | .\Morningreport_v2 -quick -html | out-file (“c:\work\{0:yyyy-MM-dd}_morningreport.htm” -f (get-date),$env:computername)’ “

    1. Jeffery Hicks says:
      March 26, 2012 at 11:49 am

      I would use complete file paths. I suspect PowerShell can’t find inputservers.txt and may not know where the script file is either.

      1. Eric Iverson says:
        March 26, 2012 at 12:58 pm

        No Joy:
        C:\>MorningReportD.Bat

        C:\>powershell -command “& ‘get-content C:\InPutServers.txt | C:\Morningreport -quick -html | out-file (“c:\work\{0:yyyy-MM-dd}_morningreport.htm” -f (get-da
        te),$env:computername)’ ”
        The term ‘get-content C:\InPutServers.txt | C:\Morningreport -quick -html |
        out-file (c:\work\{0:yyyy-MM-dd}_morningreport.htm -f (get-date),$env:computern
        ame)’ is not recognized as the name of a cmdlet, function, script file, or oper
        able program. Check the spelling of the name, or if a path was included, verify
        that the path is correct and try again.
        At line:1 char:2
        + & <<<< 'get-content C:\InPutServers.txt | C:\Morningreport -quick -html |
        out-file (c:\work\{0:yyyy-MM-dd}_morningreport.htm -f (get-date),$env:computer
        name)'
        + CategoryInfo : ObjectNotFound: (get-content C:\…v:computernam
        e):String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

        Checked the spelling of the name, or if a path was included, verified that the path is correct.
        All are as the should be and do exist.

      2. Jeffery Hicks says:
        March 26, 2012 at 1:18 pm

        I missed it before but you need to put your command in braces:
        C:\> powershell -command “& {get-content C:\InPutServers.txt | C:\Morningreport -quick -html | out-file (“c:\work\{0:yyyy-MM-dd}_morningreport.htm” -f (get-date),$env:computername)} “

  5. Eric Iverson says:
    March 26, 2012 at 1:51 pm

    This works except for the dating of the file.
    powershell -command “”

    You are very quick to answer thx again for the help

    1. Eric Iverson says:
      March 26, 2012 at 2:04 pm

      Oops the command line did not come through _
      C:\ >powershell -command “”

      1. Eric Iverson says:
        March 26, 2012 at 2:05 pm

        Try again –

        “powershell -command “”

    2. Jeffery Hicks says:
      March 26, 2012 at 2:05 pm

      You might need to use single quotes because the entire command is enclosed in double quotes. Also, were you planning on using the computername in the file name? What you have now isn’t using it because you don’t have a place holder. Is this more what you are after?

      (‘c:\work\{0:yyyy-MM-dd}_{1}_morningreport.htm’ -f (get-date),$env:computername)

      1. Eric Iverson says:
        March 26, 2012 at 2:10 pm

        Actually… No….. What I would like to output is:
        “C:\work\2011-03-26_morningreport.htm” (This is a file of a list of servers “InputServers.txt” that I would like the status of each morning.)
        I will give this a try.

      2. Jeffery Hicks says:
        March 26, 2012 at 2:12 pm

        Are you expecting one report with all servers or one report per server?

  6. Eric Iverson says:
    March 26, 2012 at 2:15 pm

    Yes…. Exactly what I am trying to accomplish

    1. Jeffery Hicks says:
      March 26, 2012 at 2:21 pm

      You answered yes to both questions! 🙂 Here’s my batch file that works:

      @echo off
      powershell -command “& {get-content c:\work\input.txt| C:\Scripts\Morningreport.ps1 -quick -html | out-file (‘c:\work\{0:yyyy-MM-dd}_morningreport.htm’ -f (get-date)) }”

      This creates a single report that includes all computers in the input file. If you want one report per server, then you’ll need to use a ForEach expression.

      @echo off
      powershell -command “& {get-content c:\work\input.txt | foreach { $comp=$_; C:\Scripts\Morningreport.ps1 -quick -html -computer $comp | out-file (‘c:\work\{0:yyyy-MM-dd}_{1}_morningreport.htm’ -f (get-date),$comp) }}”

      The powerShell command needs to be all on one line when used in a batch file. I use the ; to indicate the end of a command.

      1. Eric Iverson says:
        March 26, 2012 at 2:28 pm

        Sorry…. What I meant was “expecting one report with all servers ” Very good examples I think I can get it from this.

        Thanks again for being so responsive.

      2. Eric Iverson says:
        March 26, 2012 at 2:33 pm

        Yesssssssssss that was it. Thanks for such a great PS script.

      3. Jeffery Hicks says:
        March 26, 2012 at 2:43 pm

        Thank you so much for your interest and support.

  7. Joe Saphiloff says:
    April 16, 2012 at 2:10 am

    Very nice work, thank you for sharing.

  8. Neil McLoughlin says:
    August 1, 2012 at 7:19 am

    Hi great script, exactly what i want. How can run the report so it only outputs the event log entries section?

    1. Jeffery Hicks says:
      August 1, 2012 at 7:50 am

      There isn’t a way without rewriting the script. You can always run Get-Eventlog and pipe results to ConvertTo-HTML.

  9. Shakiel says:
    August 2, 2012 at 7:12 am

    Awesome even works on my Hyper-V boxes.

    1. Jeffery Hicks says:
      August 2, 2012 at 9:20 am

      Thank you.

  10. Mark Brabson says:
    August 5, 2012 at 6:22 pm

    OMG! I am…or make that *WAS* writing this script myself and found yours while looking for the best way to test various open ports. You have saved me a good deal of time (which is in short supply lately) – I gotta buy you a beer sometime! 😉

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d