HTML Reporting with Powershell Part 1 Creating the Basic Report

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Mike and welcome back to the channel in today's video we're going to be looking at creating an HTML report using Powershell and this will be part one of two videos here so we're going to have one creating the basic report which is in essence is going to focus on the Powershell side of things like how to actually put together a complex HTML report and then I'm going to put out a part two later on this week which is going to be looking at making the report look fancy so you know bringing in like cascading style sheets or css settings and stuff like that okay so with that let's uh move over to the lab environment so for today I'm going to be using uh Visual Studio code and Powershell seven for putting this together but uh realistically if you still use the ISE or Powershell five or whatever that would be perfectly fine as well okay so let's first of all look at what uh what creating uh HTML basically is here and it doesn't necessarily have to be an overly complex operation here so first of all let me uh take my Powershell console here and just make the font a bit bigger so everybody has an easier time of being able to see this all right there we go okay and we'll clear the screen and so with HTML reporting you're relying on a commandlet called convert to HTML right um and so that commandlet has been around for man I don't know how long um at least Powershell 3 with Windows 7 but I did I do believe it's older than that I want to go out in a limb and said it was in Powershell two uh they came out you know before that uh so with that being said how do I use it so let's say for instance you have something that's creating some type of output so in this case let's say I'm going to do get service name and maybe grab a bunch of services that start with the letter b and for whatever reason let's say I want to take this and I want to make an HTML output out of it so you know there's a lot of different commandlets that are there for doing the output side of things for taking objects that are in powershell's Pipeline and making output out of them okay so you may have seen uh convert to CSV export CSV export CLI XML um uh convert to Json for instance and so all of those commandlets could be used and we also have convert to HTML okay so if I wanted to use that uh first of all you probably want to make sure when you're exporting or you're converting you're recognizing the amount of information that's on the objects in the pipeline okay so in this case I have this commandlet running and it's producing let's see one two three four five six seven eight nine okay so let's say we have nine objects that are in the pipeline now each of these objects you can see on the screen here it has status name a display name but keep in mind those are not necessarily all of the properties that are there right so if I were to like let's say uh pipe this over to maybe uh select object and property star let me see all of the properties uh you could see for like each particular service it's got a lot of stuff on it okay so I don't necessarily want all of this exported out into a file okay so I might want to be selective here so maybe if I just want like name and Status let's say oh and maybe uh maybe start type okay so oops that was supposed to be a comma not a period there we go all right so in this case I now have an object but that object just has three properties okay so if I again kind of look at this and get member you know I have my object and the three properties that are there all right so let's say that's now what I want to send out to HTML so all I have to do with this is to convert to HTML and then in the powershells pipeline it'll format it away from a.net object which are normally what are in the pipeline and it will write it out as a bunch of string data uh creating HTML objects so if you notice here you can see it's creating a table you can see that opening element the closing element there we've got all the table rows here um we could see the uh the header the opening of the HTML document the closing HTML document down there closing body tag opening body tag right there so you basically have an HTML document here so when you run convert to HTML just on its own it will create a complete HTML document all right so all I have to do now to make a file out of this is to send this or pipe this over to out file and give it some place to go so I'm using the stuff folder here and I'll just call it out one dot HTM or HTML either file extension is is fine so I do that and then if I come in here and let's go find it so C colon stuff and there's my out1 HTM so I pop that open and I can see you know there's my HTML output that's it's awesome right I couldn't ask for a better looking report if you tried okay so everything is good there now where some of the complexity comes in is if you wanted to create multiple pieces of output so imagine if I wanted to maybe grab the services and then maybe I wanted to grab I know processes to go with it okay so so this again by using convert to HTML creates a complete HTML document and if I were to do something like get process and maybe just grab the first 10 here uh this if I were to take this and send it to convert to HTML again that would comp you know make a complete HTML document as well okay so if I go kind of all the way up to the beginning here I can see there's the opening HTML tag right there and then if I scroll down oops go down too far uh scroll down I can see the closing HTML tag right there so that makes this a little hard if you wanted to combine different pieces of output together okay so what I'm going to do in a script here that I'm going to start writing in a moment is I'm going to take and do a user script so basically it's going to query active directory and find a few different pieces of information so I'm actually going to be running like three different queries and I'm going to need to take those three different pieces and make one HTML document out of it so kind of the same thing here imagine if I wanted to combine get process and get service together so I want them both to output and combine this together so in order to be able to do that you need to dig a little deep onto the convert to HTML commandlet so if I look at this commandlet I can see that it does have a few properties to play with okay so you can tell it like what particular properties you want to be included so if you didn't want to use like select object like I was using to to figure out those properties you can add a header onto this you could add a title uh the body so that would be basically the the core part of the report here you could have things you're piping in input objects so that would be like the the data I was piping in like get service or get processed uh and the the part I want to focus on here which is very useful when you want to combine things together here is this fragment parameter so with fragment you can create the different pieces of HTML and then in essence combine them later okay so for instance if I took the uh the get service one here and instead of just kicking out to a file let me just have it write the the Powershell right to the pipeline here again or the HTML code right to the pipeline uh you can see here it's doing the complete HTML so there's the opening HTML there's the closing HTML so it's making a complete document however if I tell convert to HTML to make a fragment notice the fragment it just makes the table okay so what I could do is I can utilize that I can bring multiple fragments together um into this uh let's see where is it here into this body parameter see how body takes multiple values right so I can combine multiple fragments together in order to make one HTML document which is ultimately what I'm going to end up doing here okay so we could also control the fragments you notice there's an as parameter here so you could do a table or a list and we could do different ones depending on on what our what our needs are if you will right so that's kind of where we're going to begin here so I'm going to pop open Visual Studio code or vs code we're going to do a new file this is going to be a uh actually ruined about there let's just do a text file let's pick Powershell as the language and we're now making um Powershell I don't need the getting started one here and before I do anything else let me just go ahead and save this I'll save this in my stuff directory here and maybe we'll call this um a user report about that all right and then typically with all of my scripts when I begin them I typically start with uh binding okay and then we have some type of parameter block that we're going to use right um so the first parameter uh that I'm probably going to see myself creating is obvious I need to to query user right so how about I just make this as a string and we'll just call it uh user okay will be our parameter all right and we'll leave it at that okay a very simple parameter block all right now the next thing we're going to need to do is we're going to need to grab some information all right so I'm going to query active directory so this computer does have the uh the active directory On rsat Tools installed on it so for Windows 10 if you don't know how to do that you could right click the start button to bring up the Winx menu here the go to like apps and features uh go to optional features and then in here we're going to add a feature and if you go down into here you'll see a bunch of rsat ones here okay so the active directory one's not showing up because I already have it installed but this is where you could find it so if you look at my installed features you can see right here I've got the rsat active directory domain services and lightweight Services tools here add to this box here's a Windows 10 box it is joined to my active directory domain my domain name it my domain name is chassis tac.com right so that's where I am administering from all right um now with that as well uh let's open up users and computers and we could see again I have a few kind of sample users here so the one I'm going to make the report on is this Jeff Kent user and in Jeff Kent I have a couple things populated in here uh so for instance if I look at uh uh the let's see yeah so I've got the telephone populated uh profile uh so I've got a few you know pieces uh set up in here so I've got the title the department uh the manager Set uh things like that right so first of all here we want to go and and kind of have an idea of what information let's say we want to go get okay so I know I'm going to be doing a get 80 user query so I'm just going to kind of play with that in the console here so if I type get 80 user and the identity here of 80 user uh J kept that's the the user the same account name for that user account and I can see the information that comes back now some of the things I might be interested here like for instance I see the name right I'm probably going to want that I probably want the same account name uh maybe I want to do something with distinguished name here I'll figure something out with that in a moment uh we could see maybe the user principal name uh maybe I want to grab the email address email address was not really populated here maybe I should uh populate that one uh email Jay Kent at now you might not have to populate that in your environment it might automatically do it but anyway so so let's say I'm grabbing that all right now notice here with get 80 user if I pipe this over to get member there's only like 10 properties that come back okay so that's kind of a downer for me right I want some other things here like I wanted the title um I wanted the phone number I wanted the manager uh the department and none of that is returned by default in this query so you have to tell active directory what to go get so if you want it to get more stuff you can tell it via the properties parameter and tell it what extra stuff you wanted to come back with other than the 10 properties that it gets by default right so in this case like if I wanted a title I could tell it to go grab the title property all right and notice that that's now returned as well okay or if you just want to be lazy and tell it grab all of the properties just throw a a wild card in their own asterisks okay so that'll go grab everything okay so now I could examine this and see what properties I I literally want to bring back okay like not properties I want to bring back this is bringing back everything but what properties do I want to put in my report how about that Okay so we've already established we wanted um the name right so we have um a name right here right and we probably wanted Department uh so departments right there and we wanted uh let's see I'll probably want like uh last log on date okay when's the last time uh Jeff log on uh the mail now notice it's not email see how it's it's titled as mail so sometimes the property that you see here the name of it here doesn't always match the actual ldap uh property value okay so this is another reason to go and look at this so you make sure you get your property names correct so mail is actually a male all right um and last log on date again was last log on date uh let's see so we also wanted uh the phone number so notice that shows up as mobile right so that's what I want to go grab uh manager okay so that's correct uh let's see and see I wanted um looking for oh yeah here's script path right here okay so I wanted that as well so that was the value that went with um uh let's see under right right here uh log on script so that is a property called Script path okay so that's what we're grabbing there okay so those are the the things we're gonna go and put into our report here so those are the properties that I'm going to want to utilize right so let's start off here with that so if we do a get 80 user and the identity would be from the dollar user parameter and we want to tell it not partition we want to tell it properties star all right and then from there we're going to bring it over to select object so I can just kind of key in on the properties that I want right so I wanted name I wanted Department I wanted a script path uh we wanted mobile uh let's see we wanted manager title mail and maybe like uh a last log on date right where the properties that I wanted here it's a nice little list so a nice little list here Abby make the oop the ISE if I could get to the end of the ISE there just to drag it there we go um and yeah different okay and so last log on date all right so that looks good there and uh so that should give me the information so so I'm just going to save the script for a sec here I'm going to go into my Powershell uh console here uh change the directory over to C colon stuff so you calling stuff and let's go ahead and run this user report um user Jacob okay so we got name Department script path Mobile manager title mail last logon okay so that looks good um I wanted to do something with distinguished name as well um so let me just tack that onto the list there distinguish name and again save that and let's try running the script again uh oh and I didn't spell distinguished right distinguishing that should do it Funny How spelling is important right all right so so that's let's say the first part of the report here now I keep mentioning parts to the report well what else am I going to do I'm also going to want to grab the group memberships so if you look at a couple videos I posted earlier this month I did one which was uh converting a DOT net script into a Powershell script and that happened to find a nested group memberships and then I did another video where I improved upon that or I added in some different output some different parameters so I'm basically going to do two different queries with that script if you will I'm going to do one to find the direct group memberships and I'm going to use another query of that to find the nested groups so that's basically what my report is going to look like so I have this information that's going to be the raw user facts that's going to be the first section of the report that I'm going to have a section for the direct group memberships and then I'm going to have a section for the nested group memberships and if we look at Jeff Kent here if I open up his user account if we look at member of you see he is listed as a couple you know a couple direct members of these groups here these are Global groups hence the GL uh in their name and then these groups themselves if I go look at them these PL groups uh they are members of other groups as well so so notice this this marketing one is a member of this Universal group called univ marketing and then that is actually a member of a domain local group uh and then this one right here is that's not nested uh where's the one that is um so again this one here you could see a member of that domain local group all right so a few different uh group structures here and here's sales you could say that's a member of the domain of a domain local group as well so there is some nesting going on here and so I want to put all of that into my report here okay now the first thing that I want to do though is well I guess I've already got this kind of like situated out here and this is actually how I want the output to look this is list output where you got the name of the property and then the value so name of the property value name of the property value and so on okay so that's fine to there and let's say that's uh you know that's what I want to do Okay so some of it though I might want to clean up a little bit um so for instance like you take last log on date uh maybe I just want the date and I don't necessarily want the time okay so I could utilize a method on a date time object called two short date string to grab just this piece of info and toss this because this is a date time object that's what lasts log on D produces uh and the rest of these are just plain old strings right so I could manipulate to that so for instance I might want to take distinguish name and just to grab the this piece out of it right here okay so in this case I want to make a property called OU and that would be the name of the OU that the user is in right uh so let's say I wanted to clean this one up as well so so we'll do a little work to these two properties here okay so how do I go about doing that well from an HTML perspective it has absolutely nothing to do with HTML okay so just throw that out there this is just modifying the information that happens to be in powershell's pipeline okay so um so how do I again how do I go about doing that um so first of all let's clean up the select object line a little bit here uh where I probably want these things even though it doesn't matter notice in my output see how they're all kind of like lowercase right and they're it's using the format of the property the exact way that I typed it in on select object so if I want to kind of make these look a little fancier I can uh just kind of do a bit of capitalizing here okay again if you wanted to make it look nice I mean you certainly don't have to uh but if you're going to go to the hassle of making an HTML report it might uh be advisable to do right so let's maybe do something like that actually the last two I'm not even going to bother with because I'm going to do something else with those all right so first off so let's go ahead save that and then we'll try running the script again and notice how they look nicer now okay so that's that's cool right there okay now I mentioned I want to do something else with these so with these we're going to do something called uh calculated properties so we're going to do a little work in there okay and to do this so I don't have to keep scrolling all the time scrolling back to the end scrolling back to the beginning I think what I'm going to do is I'm going to take select object here and after let's say mail I'm going to do a carriage return you can do that that's allowed in the in you know the the scripting environments here so you could do Carriage returns after pipe symbols after semicolons after uh commas uh and Powershell still treats these two lines as one line of code all right and the reason why I want to do this is because I'm going to be doing work to these two properties so I'm going to kind of put them on their own line to make it stand out a little bit okay so and hence the tabbing here uh just to kind of again make it stand out a little more as well I should have only done one tab depth though let's do that okay so to make a calculated property I I basically make a hash table so I start with an at sign uh open a curly bracket and then close the curly bracket and then everything inside of that is a calculated property now with the calculated property you need you're basically like think of it this way you're creating a new property so I'll start with what I want the name of my property to be so name equals and let's call this last logon okay so that's what I want it to be called then I've got a semicolon and then I have my expression equals and then that is a script block all right so we're going to go put a script block around this now something to note with script blocks is when you're in a script block you can use the variable that represents the objects in the pipeline okay so remember this this thing here is still a part of Select object and so it's seeing the objects that were piped in from the previous commandlet all right so if I use dollar underscore or dollar PS item that's fine uh either one will work and so I like using dollar underscore I do a DOT as the separator I want to grab the data out of the last logon date and from that I want to call the two short date string method with no arguments on it okay so that is one that has an empty argument list okay so that looks good let me go ahead and save this and let's make sure I didn't blow anything up so let's run the script again and notice now last log on looks good all right so we got that piece now the next one is going to be a little more complex like I need to go grab this piece of information out of this overall string here got it now this will vary depending on the user uh that I happen to utilize so in this case I need to grab everything from here okay so I need to ignore the string up to here grab this and ignore the rest of the string going out now the problem that you run into is if your user account is in use is in the user's container um the distinguished name has CN equals users however if my user was in like groups here uh this would be o u equals groups like The distinguished name is different okay um so that's something like to um to factor in when you're doing this is your distinguished names might be a little different depending on what's going on here guys so like when I've got g l i t so let's maybe do I get 80 group and identity g l i t yeah see notice here how the distinguished name so for Jeff Kent it was c n equals users but notice how the distinguished name periods o u equals and then that's the name of the OU so so the first part's fairly reliant on it's always going to be c n equals right so that's you know the name of the group or the name of the user that's always going to be CN so that's like common name or canonical name okay CN so that's always going to be that and then if your object is in a regular OU it then starts with o u equals and if it's in a container so that's uh basically not the same as an OU that's in a container it starts with c n equals so the containers here how do you tell the difference you basically look at the symbol here so if you look at built-in computers foreign security principles manager service accounts users those are all containers uh groups and domain controllers those are organizational units and if you notice the symbols here are different okay so an OU has like a little something inside of like the folder looking icon here and a container does not okay now you might think well how do you you know how do you make them usually when you make an OU like if I come up in here and right click and do a new organizational unit and I'll just call it test just for demo purposes here see how it makes that same symbol there so that's truly an OU and most of the containers are ones that come with active directory by default like you've never actually made them so when usually we make structure in here we're usually making OU's and the containers are the the default locations that came with the active directory environment okay so with that being said how do I grab like this piece right that's all I'm interested in and if I was doing it with this I would just want to grab this okay so how do I go about doing that well you can actually use something in regular Expressions called capture groups so if you're not familiar with regex we want to describe this text this text string here so let me go ahead and go out to the internet here um and my apologies this guy does not have internet access let me uh bear with me one sec let me change over to my DC that does have internet access um and let's uh Crank that up and let's go to a site called Reg x101.com and my test string was right there okay so that's what we're playing around with and I want to craft together a regular expression that matches this as close to I can all right so basically how do I do that well there's a whole bunch of if you look kind of down here there's a there's a lot of different quick reference things uh that tells you know like a single character or single token stuff like that so you have different ways of describing the data so for instance I start with uh shift six uh to do that uh I can't remember what that character is called I always call it a party hat but I think it's like a carrot I think is what it's called so that describes the beginning of the string and you can see here it kind of in our test string and kind of match that so then I'm expecting to see c n equals oops c n equals and notice how it highlights that part so that's what I've described so far now the next will vary depending on the name of the user so there could be any characters in there so to do any character I could use a period for that so I put a period in and see how it matched on the J and then I use a wild card I'm going to use an asterisk which matches so basically I'm saying with the period I'm saying any character and then with the asterisk I'm saying multiple of them okay now notice here as I hover over the asterisk look up in this qualifier here let me hover over it again and look at the very bottom line see where it says greedy in parentheses all right so I don't want this operator to be greedy I want it to be lazy okay so what am I talking about with greedy versus lazy um so if I were to say like for instance describing the strengths if I say any character multiple of them I want it to stop at the comma right so if I just put a comma in there see how it gobbles as much as it can stopping at a comma so I don't want it to stop at the last comma I want it to stop at the first comma so I want this to be a lazy wild card not a greedy wild card so before the comma I put a question mark there and that turns that now into a lazy uh quantifier so you notice right at that last word in the in the the black box there it says lazy okay and notice what it matched up with now so that now got me the username part and then I want to keep going so the next part might not be c n remember in my example here I you know it could be o u equals right so I want uh any any word character so any letter so that would be uh backslash w and then to backslash W and then an equal sign okay so that's now matched up on the beginning part here and it would match up if this piece right here was c n equal or OU equals so then I've got the username the the OU part that I want so that would be again any character multiple of them I want it to be lazy uh to the next comma and then any character multiple of them okay so now what I do to isolate this part right here is I make something that's called a capture group so in the capture group part you take the part in the regex query that that is the part you want to capture and you put parentheses around it so I wanted to capture uh this piece right here right so I wanted the any character multiple of them as lazy right so so that goes off of users here and notice how it found that see how it matched up on group one and it's showing users right so now uh if I were to grab that other text string here bear with me I'm not going to show it on my screen but I'm just going to go grab that other text string with the group one and try pasting that in I see how it matches up properly on groups as well okay so so that kind of it it fed or it's reading the string correctly which is uh the goal here right okay so now how do I go about utilizing that so let me go grab that regex and let's switch VMS back to where we're writing our script and in the script itself here uh let me just go paste that in and we're going to do something with that in a moment here so let me just wrap it around um wrap it around some quotes here okay just to kind of hold on to it okay so now we want to make um another calculated property out of this so I'll start off with the at sign open uh we need to give it a name name equals and let's call this uh I'll just call it ou right how about that and then uh backslash and then expression equals and then we got our script block and then this whole thing is going to be in that script block and then a final quote there just to close the calculated property okay now when I'm doing name and expression uh understand that a lot of people abbreviate those so expression could just be E equals and name could be like four different things in here could be n equals name equals L equals or label equals there's a lot of different stuff you could put in there okay so then we want to take the object in the pipeline the distinguished name property and we want to do replace and this is the from string which is our regular expression with our capture group and then after that we're going to do a comma and then this has to be single quotes because you call a capture group uh by a dollar sign so I do dollar sign one to tell it I want the first capture Group which is going to be this piece right here all right so let's go ahead and save that and let's run to that and oops that's not running it hold on there we go cool so we've modified last logon and we added um a property here called OU I so that's going to be the first part of the HTML report okay so now let's go about making said HTML so in order for this to work properly we are going to need to save this as an HTML fragment all right so first things first we're going to have to take the result of this and we're going to after the select here so that whole thing is Select object let's just do a pipe and let's bring it down to the next line here and we are going to send this uh let's see convert to HTML and we're going to want a fragment out of this and we're going to want to format it as a list all right so and take the whole darn result here and save it in a variable so maybe this will be dollar frag one okay now is about the time I start making like Fraggle Rock jokes and stuff like that if anybody's familiar with Fraggle Rock You are probably by age range I'm 49 years old and I can remember watching Fraggle Rock uh as a it was like an equivalent to like the Muppets uh back when I was a kid so if anybody knows about Fraggle Rock feel free to make a comment uh in the comments here uh for those of you that have no clue what I'm talking about you're probably either a lot older than me or a lot younger than me anyway so Fraggle Rock was pretty cool back in the day and granted I think it was like six years old but you know I thought a lot of things were cool back then all right so that gets this first part out of the way okay now um let's let's go and let's say this was the only part I wanted to do okay so let's just kind of finish this up uh just to show this this first piece here from beginning to end okay so now uh let's say we wanted to again ultimately I'm going to modify this to add more stuff to it but let's do convert to HTML on its own uh we want a body of that fragment frag one and then let's say we want to take this kick it out to a file uh and let's do I know I'm hard coding a path there just bear with me I'll make that better later on and let's just call this test1.htm all right so Ctrl s to save this and then let's see what we got okay so first of all let's go ahead and run the script now it should produce no screen output right now right because I'm saving it all to a file so let's go oh there's out one no I did test one there we go so let's open up test one and what do you know that there's all of our information so it so it read that fragment in no problem and made HTML out of it all right so that's cool so that gets our first part done Rock in here okay now probably the next thing I'd want to improve on would be this right here I don't want to hard code uh a path in there okay so what I could do with that is we could throw up in the parameter block let's make another parameter this will be string and then maybe we'll call it uh file name or how about um yeah let's call it uh h tml file name yeah that makes it sound fancier okay and then down into the bottom part here uh what do I want to do with that well I want to utilize that like here and then maybe I'll set the script up so it saves it where the uh the current prompt is where you're running the script from so whatever the the Powershell working directory is okay so that would be in something called p a variable called PWD which is one of these automatic variables that exists in Powershell uh so let's say so the um so the out file again I didn't put the parameter in there I probably should so let's do um so we're going to want to do let's see file path and then let's Pro quote in there uh we want dollar PWD uh and then the backslash and then uh dollar HTML file yeah so let's try that as the path all right so let's save that and then so now uh with the HTML file path how about we'll call this test2.htm run it go look hey we've got a test two and it's got the same stuff in it perfect okay so we're rocking and rolling here all right so if you don't want to get overly complex with this that could be one way of potentially saving a path where you want to put something all right so the next part here we want some group information right so in order to do that I want to take advantage of another script that I wrote earlier uh this uh this get groups one here okay which you feed it um a Sam account name and it will spit out uh the group membership so again I added a few parameters to it which will grab the direct the nested or the all uh so right now I have this in its own Standalone script so if I were to play around with that um I could do this get uh get groups 2 and then Sam account name uh J Kent and notice how it spits out all of the groups uh the direct and the nested apologize for that little warning there uh the direct and the nested and I could tell it uh different output mode so if I want just the direct groups I could spit that out or if I want just the nested it could spit that out as well right or if I want to do output all um so again if you're wondering how I put this together go check out my videos on converting a.net script into a Powershell script there's two videos I have one where I do basically the conversion and then I have another one where I'm adding improvements like this output parameter so that's not in the original.net script okay so let's say I want to utilize I don't want to call a script though I mean ultimately I would probably be putting all of this stuff in functions in a module but I'm just kind of doing development here so what I think I'm going to do is I'm going to take the code of the script here this get group script and I'm going to copy it so highlight control a to highlight all control C and then I'm going to go to user report and at the beginning of user report I'm going to make a I'm going to make a function out of this so I'm going to throw the word function row function in there how about I just call it uh nested and then I open the function and then close it right so there's the opening then there's the closing right there and let's go paste this code so control V and that's now inside that function right and since I don't want to be staring at it I could take the function here and you know let's say we just want to like minimize it okay so all of that code is in this function called nested all right um so that way it now kind of lives in this script if you will all right so now I want to grab that information and I want to put that in another fragment that is ultimately going to be in my HTML report so let's do um uh dollar actually before I put in a fragment let's make sure it works first right so so let's call the nested function and the uh Sam account name would be the same as I was calling up here for identity right so dollar user and um output mode I wanted to just grab the direct group memberships first all right so that's what I want to go grab and I'm just going to leave it like this okay so let's do a save on this and let's go run the script and um now I don't really care this is not going to be in the file I just want to see if the screen output is correct and it is right so yeah so it wrote stuff to a file but this was written to the screen and it outputted correctly so you can see that like right here right so now let's capture that uh and use that so let's store that in frag 2. and let's uh let's use the same convert to HTML [Music] all right except this time I want to do a table out of it and then we could go down to the body here and add that fragment onto the body okay like so all right so we're adding another piece into there all right now let's go give it a shot I did a control s to save it I know you can't see me do that it's keyboard shortcut but I just did control s and then let's go and try and run this and maybe we'll put this in another file here so let's do test three if you don't change the file name it will overwrite whatever file was there by the way um so we'll go ahead and run this and oh we're getting we're getting some errors here okay so convert to HTML cannot convert system object to type system string required by parameter body specified methods not supported okay so what's happening with that is everything worked perfectly fine when I just had one variable in on the body when I just had frag one there so it reads it fine that way when you start combining multiple string objects together or multiple variables together they're each being seen as arrays not as strings because they have multiple things in them and that's kind of freaking out the body uh parameter here so what you do to fix that is in your fragments whatever you're doing with the fragment you finish it up with an out string so each fragment is outed as a single string so if I throw those lines onto there we could see of that information okay so out string and out string all right so I just combined those as the end of the different frag lines here so now if I go run to this um it did not error which was nice and if I go look at html3 we could see that um uh there's the first part which is awesome but what the heck is that so length 22 and 8. so that's happening with this uh with this line right here okay so the problem that's happening is my kind of my my script or my my function here which kicks out the group memberships it outputs them as strings right so they are in string format so if I go kind of run this here you could see the groups and if I pipe it to get member um we could see that there's uh let's see so it is producing strings right all right now the problem with a string uh is convert to HTML is very literal it will literally take whatever objects are in the pipeline in this case string objects and it will look at those objects and grab the properties into them okay and with a string object the actual string is not one of the properties that that's kind of one of the weird things with strings like if I were to put let's say like dollar a equals uh I don't know Mike okay so let's say that's a string right and if I just kind of Hit the string it enumerates the kind of the the value of the string object but if you look at this by sending it so first of all send it to get member you could see that a string object has a property inside of it which is length which is the length of the string so if I were to do something like uh select object uh property length uh see how it spits out four which was the length of the string you know m i k e that's four characters so what you need to do if you have a pipeline of string objects which is what I have here before you hand it off to convert to HTML you have to take those string objects and make them a different kind of object so you can actually do that by doing a calculated property similar to what I did up here so let me go over here and let's uh let's put convert to HTML down on its own line and then let's throw um let's throw the next line here let's do uh select object and then property we're just going to do uh some calculated properties here so so no uh uh no big deal so let's try uh let's do an at and then let's see what do I want to call this let's do name equals and then maybe we'll call it uh Direct groups right and then semicolon and then my expression equals so I'll just do the E equals there and for expression all I'm going to do is just grab the object that's in the pipeline or objects that are in the pipeline okay and then we'll pipe that over to convert to HTML so this is all one you know one big line here I just have it you know Carriage returned off the pipe symbols here all right so let's go give that a shot so we save that let's go run it I'll overwrite the file that's there and let's see if we have the values in here sweet there we go all right so we got um that we got that very nice all right so that gets us um the direct groups and then all we need to do now to get the nested groups um is just kind of um uh duplicate this section here except changing the output from direct to nested um to grab those so remember those were again just different parameters on my script that's being called as this function here right so let me uh grab this line here and let's call it frag three and for output I want the nested groups so again it's reading that because remember in my script I literally have um you know remember this this this this script here is what's loaded in that function called nested um I have a parameter called output which is can either have direct nested or all right so let's go back over here so that's in frag 3 and let's change the name of that so that would be nested groups and then we'll throw the comment in here and tell it to grab frag three as well and save this and let's go ahead run it I've made the file let's go look at the file and there we go so we've got the name there so there's the information from get 80 user here's the direct group memberships for that user and here are the nested group memberships for that user all right and um and there we go so that's uh the the the crude part of the htfl report here I know it doesn't look all that fancy um so again I I understand that uh but again we gotta start somewhere okay so again this was the um so this was the code here kind of minimize that down so this was the code um since I'm gonna be doing a part two to this video I'm not gonna put a link to this script here yet because it's it's we're technically not done with it but this video is already up to an hour here so hence why I wanted to do a part two after the fact okay so this is where we're going to leave it for now with the raw data in HTML now I know it looks like well it doesn't look very fancy uh but that's enough to get us going here and maybe for some people this is awesome right like hey Mike that's the best HTML report ever uh because I have you know three different queries that I'm pulling information in as fragments and that's exactly what I was looking for right so that's understandable however if we want to fancy this up we're going to need to do a little more work to it so that's going to bring bring in using some HTML tags using cascading style sheets things like that so we're going to save that for part two of this series here so with that let me bring this one to a close so thank you everyone if you hung out with me till the end here and watched everything if you like the content again I am a new Channel please consider liking and subscribing especially subscribing subscribing really helps the growth of my channel uh so if you could do that be greatly appreciated and be on the lookout for part two where I'm going to be adding some HTML tags adding some cascading style sheet information in here and that kind of stuff so with that have a good one and we'll see you in the next video
Info
Channel: Chasse TAC
Views: 1,444
Rating: undefined out of 5
Keywords:
Id: S-IFeyhcEaQ
Channel Id: undefined
Length: 63min 17sec (3797 seconds)
Published: Fri Nov 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.