PowerShell Tutorials : PSWriteHTML - Part 1 - HTML Reports made easy

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to this Powershell tutorial in this video we're going to be taking a look at a new module that I just discovered uh recently and we're going to be having a few other videos with this module I just found this module like a couple a couple days ago I haven't done too too much with it but I want to show you guys how much easier it is to make very nice HTML pages with just a very simple understanding of how this module works and I'll be making more videos with this module because there are a lot more things that you can do with this module with HTML reports dashboards and emails so I think this module is kind of cool it's called the PS write HTML module and we're going to be seeing some simple HTML outputs that look very very nice that are very easy to do some formatting on so let's go ahead and let's take a look at how to install the module and just use the very basic uh HTML table and the out HTML view from this module to create some pretty nice HTML reports out of the box so the first thing we're going to want to do is install the module so we're going to want to do install module and then the name of the module is PS write HTML and we're just going to want to allow the clobber and force you're just going to want to run this this may take a few seconds it doesn't take very long to install and once it is installed you are all good to go and we can actually start using the module so the first thing that we're going to do is just show you a very simple example of a get service commandlet pumped into an HTML report of sorts so let's actually go ahead and take a look to see how nice we can actually make this from the basic version so what we're going to want to First do is just store all of our services into a variable here I'm going to call my variable services so we're going to make this equal to get service and I only want a limited set of the information so I'm just going to say select name service name status and start type all right and we can actually go ahead we could actually just run this right away you will see some red on my screen um because we can't actually query those services but here we are we actually have a list of our services that are running on this computer right now and we have the start type and the actual name of the service so let's go ahead and let's make us a new HTML table so the first thing that we would want to do is if we're creating a report that we would actually want to send to people is we would then start with this new HTML commandlet and then what we're going to want to do is actually do an open and close curly bracket here right off the back right and then in here what we're going to do is we're going to do a new HTML table so as you can see there are a lot of opt-ins in here that we can actually do um we're also going to be taking a look at just the table today um but they actually are very very nice uh by default so I think this will come in handy for a lot of different people here and I'm going to be making a couple more videos on this module accepting this module is very neat on what you can actually achieve uh so once we create our new HTML table our data table that we're going to be pointing to is going to be our services and we're going to give it a title here what I like to do for my title is if I was making this for my servers for example I would just go ahead and put a variable wrapper in here and go into the environment variable and put computer name and then do services so this would be a HTML page of all the services currently running on my server and then what we're gonna do for now is that's really all we're going to do and then what we're going to do is we're going to add a little parameter after here and we are going to say show HTML and let's go ahead and let's run this code here you're going to see it's going to actually pop up an HTML uh page here in your browser of your choice you might be prompted to pour a browser selection I have mine set to Edge as my default HTML browser so as you can see here we actually have a table of all of our services and we can actually copy these we can actually export it to excel export it to a csb export it to a PDF so if you actually click on the export to excel it will actually automatically download an Excel file if you click on the csb will automatically download the CSV file you can actually go ahead open it and you will actually notice that it is actually fully exported and fully Works nicely here um you can also change the different you can show all the rows so we can go ahead and see all the different rows you have access to a search builder in here so you can add a condition let's say you wanted it an and or an or you can actually change that here put the start type is equal to automatic and there you go it only shows me now these start types that are automatic if we want to go ahead we can even search up here thank you there it is spp we get spp service if we wanted to do spooler and it always updates as you type so it makes a very very nice page very simply off just this this is all we needed to create this very nice page and we actually have ability to do even more so what I like to actually do is set the paging length so that will set the automatic size of the pages we're just going to set it for 25 now we're going to see the differences what I also like to add is I like to add the search pane which we're going to see what this one this looks like now so now that we actually have this here let's see how it looks so let's go ahead let's run this again and here we actually have our search pane here now you can actually collapse it so you don't actually have to see it or you can do a show all and here you can actually just select automatic and it will automatically filter what you have here so you can say running and automatic will show you only the services that are running and automatic and you can see that the paging length I've set to 25 it is automatically set to show 25 rows but if I actually change the paging length here to 100 let's just run this code here now the page size will automatically show 100 rows so now we're going to be showing off 100 Services right off the bat so you can actually do these custom page sizes you can add these search panes that are very nice as you can see we can very nicely see these rows you can click on them to highlight the exact row so you can easily read all the information on it it's just a very very nice module it makes HTML reports very easy and what we can actually do is we can actually do even more so what I like to do is since we already put a title to the HTML page which if we actually go ahead and we go ahead and look at this here go and just run it again here we don't necessarily see our title so what we need to do is we need to do the new HTML title text and I like to put the same title text that I put in here and this will give our page an actual title but what we can actually do as well is on the new HTML table here we can do a pre-content and this will have to be in a script block here so we need to open close curly brackets and then what we I like to do is I like to just put a set of double quotes and put that same text but what we do is we actually wrap it in H1 tags because this will be read in as HTML so we can put H1 tags here and let's go ahead and let's see how this looks like now we can actually see we get our computer name Services we can actually see the name at the top here our our tab name also is that as well but we can actually see like it does actually it's starting to look quite nice now let's add some formatting to the table here to make it to where if it is stopped and automatic we actually do have one of those here so if we go spp we have stopped but it is an automatic so it should actually probably be running in our situation a lot of times when you have servers you'll know which ones should be running and you can add these conditional formatting rules to actually highlight the ones that should be running this way uh you can actually quickly see what there is a problem and what you can actually do with these HTML pages is you can actually send them to an IIs server and then maybe have like a home page which will have a link for all the other pages which are all going to be your servers and name them with the server name and you can have an accurate view of all the services on your server maybe it's not the best solution to Sierra Services there are a lot of other solutions that can do this for you but if you want something that is free and very fun to build up a project to learn Powershell this is definitely something I would recommend so let's go ahead and let's build out a little bit more here so we have our pre content now let's add some formatting rules so after the pre-contact here we're going to add another open and closing curly bracket and what we're going to do is we are going to go ahead and do a new table condition all right and then what we're going to do is a new table condition group here and we need to put a logic so everything that in this group is going to be applied the logic of and none or or so what I want to do is an app because I want if these services are automatic and so the start type is automatic and the status is currently stopped so I want the logic of and and then what I want is if it does happen to actually equal to True here I want the background color to be red and I want the whole row to be red all right and then we're going to do an open and closing curly bracket once again and this is going to contain our table conditions so we want to do a new table new table condition and we want to do the name so we want to do our name here as status our comparison type is going to be a string our operator is going to be equal and our value here is going to be Dot all right and then we're going to have our another one so a new table condition our name is going to be start type comparison type is going to be spring operator is going to be equal value is going to be Auto Matic all right so this actually should be good here so let's go ahead and let's run this code all right and let's look at all the automatics here and there is our stock Services here that are stopped but they are also automatic so we were able to find all of them now you can actually even put more of these so if we actually just shrink this here and we actually copy this new table condition group and we just do another one we can actually do the same and do the background color be green and that is if the status is running and automatic so now we're going to quickly see that now we've already put in a red row you can put in some green ones and there they are they're all green so now if we built it on automatic they will all be either green or red so that is awesome we can actually see all of them as well so that is all good to go now what there might be is maybe you're putting things into table that have a lot of different rows you're going to notice that the page might slow down so what you can actually do here is before the new HTML cable you can actually do a new HTML table option and then the data store you can actually pick Ajax a Json HTML or JavaScript by default it will always pick HTML if you don't put this in here so what we're going to do is we're going to pick JavaScript and let's go ahead and let's just run this code once again now it doesn't actually make the execution of the code that much faster but if we go ahead and we just view the page sorts here might take a few seconds here to load in the page source and there it is so here's the page source so you're going to see it has tons of JavaScript in here to make all of these tables and there is the JavaScript right here or the actual table so we have all of our data in here so you can see it does make very very nice and if you don't know JavaScript maybe this is another way to actually learn JavaScript as well you can easily see your data table conditional formatting there is all of our different formatting rules that we've created so this is a very very neat little module that lets you really create some interesting HTML reports quite easily and now that we have our show HTML what we can actually do now we've never actually created a file but what we can actually do now is do a file path here and then go ahead and do double quotes and we can actually output this here so what I like to do is I like to just copy the path and we're going to plump it right into here and all we're going to do is we are going to say a simple dot HTML and let's go ahead and let's run this here and we're going to see the HTML it's still going to pop up now we have a nice little name up here and we have the HTML code right in here as well so what you could do is uh similar to what I was saying earlier is you maybe you would want to pump this to your IIs server in the inet pub and name the server uh just simply the name of your actual computer here so we would have n computer name and go ahead and pump that out here and there it is what's the name of the actual server now there are things I haven't explored this whole module yet but there are entire things to make dashboards so you can make dashboards with tons of different panels with different things so you'd be able to make a dashboard with a panel with all the services a panel with maybe some information on the hard drive space on the RAM usage make a very nice little dashboard to have a status of your servers just using this PS write HTML now of course you could actually do all of this yourself as well if you know HTML CSS and JavaScript was just vanilla Powershell but it would take a lot of work and this is very very simple to actually build out your pages and have them look very nice now let's say you want to actually just make a ad hoc report you can actually use this module as well as you saw you could use this method as well this method would work you don't have to put in a file path and it will generate something very simple for you but the actual very simple is if you just did a get service and you actually pipe that to and out Dash HTML View and you go ahead and just run this line here very simple two commandlets you have your very basic option here of all your different Services you can actually open them to see more detail here so if you wanted to you can as well do these select statement in the middle of this and then just re-pipe that out to the lhtml view and if you do that you get a very similar review to what we had before minus all the pre-content and the formatting but the interesting thing is you can actually do the exact same thing here so if we actually just copied all of our pre-content and our curly bracket formatting here uh yep that's all we need and we just pasted that in here and we run this you will actually see that we get that exact same build we don't get the search paints we didn't add that um that parameter in there but if we go ahead and we just go show all rows we will see that we do have our red still and our green and you can definitely add a whole bunch of different formatting some different conditions uh you can also in the out HTML view as well you could do the paging link to be a hundred and you can do the search pane as well so we go ahead and we run this you will see uh it will be a very very similar view to what we saw before but this one just simply outs the view doesn't put it into any file and then you actually have the new HTML which gives you a little bit more flexibility on what you can actually do but if you just want something simple the out HTML view it's very very good very similar to the out grid view that you can actually use and pop out a window in Powershell and see all different details that we've seen a few times but if you guys thought this module was cool please let me know in the comment section down below if you guys would like to see more on this module I will definitely be making more anyways especially for dashboards and reports and emails I think this tool can definitely be useful to a lot of different people on this channel so I will be posting more of these if you guys have any comments or questions on anything that you guys have seen here or have any other modules that you guys would like me to take a look at please let me know in the comment section down below be sure to hit that subscribe button hit that like button also be sure to hit that notification it'll be notified when that next video comes out and I will see you guys on the next video
Info
Channel: JackedProgrammer
Views: 2,953
Rating: undefined out of 5
Keywords: powershell basics, powershell, windows powershell, programming, coding, scripting, powershell scripting, powershell scripting tutorial, powershell tutorial, powershell email, beginner project, automation, powershell beginner project, powershell for beginners, powershell html, powershell reports, reports, powershell dashboards, dashboards, learn powershell, pswritehtml, pswritehtml module, pswritehtml html reports, out-htmlview, html
Id: gazRo-otfwA
Channel Id: undefined
Length: 22min 23sec (1343 seconds)
Published: Mon Sep 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.