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.
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.
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.
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
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.
That is what I figured. Tks
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)’ “
I would use complete file paths. I suspect PowerShell can’t find inputservers.txt and may not know where the script file is either.
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.
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)} “
This works except for the dating of the file.
powershell -command “”
You are very quick to answer thx again for the help
Oops the command line did not come through _
C:\ >powershell -command “”
Try again –
“powershell -command “”
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)
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.
Are you expecting one report with all servers or one report per server?
Yes…. Exactly what I am trying to accomplish
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.
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.
Yesssssssssss that was it. Thanks for such a great PS script.
Thank you so much for your interest and support.
Very nice work, thank you for sharing.
Hi great script, exactly what i want. How can run the report so it only outputs the event log entries section?
There isn’t a way without rewriting the script. You can always run Get-Eventlog and pipe results to ConvertTo-HTML.
Awesome even works on my Hyper-V boxes.
Thank you.
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! 😉