Now, of course,
what about if we wanted to export that into the log files as well?
So if we go back to here, and we've got Report,
we've got Logs, we want something to go into that one too.
So what we can do is I'm going to open up my structure again and go
back to Export, and then just move that across.
You can see it does the same thing except I've mapped this
into just a function, so I've got function Export‑CsvLogs,
you've got all of the items,
which is all of the objects I want to get, and then basically just add an
Add‑content and just output them somewhere as well.
So, we have a function that we could utilize.
So what does this look like?
Well, first off,
let's go and remove some of this extra information that we don't need.
So once again,
let's just copy this because this is going to take a while to
execute if we do this. Let's scroll all the way down,
paste that into there, and then what we'll do is we'll simply just reduce that
down to a smaller level, so let's use DiskInfo as the stop and then we'll get
rid of local and we'll get rid of ApplicationInfo.
So, short and sweet right now.
So there's my function. So what I'm going to do is,
well, first off,
we need to make sure that all of these variables are populated, and we
can see that the output path is obviously going to be where that's
going to go, so let me copy my function.
This is the nice thing about PowerShell functions.
Let's go here, paste the function in. Okay, so I have my function
now, so I'm going to say Export‑CsvLogs, and then you can loop
obviously through the various options,
so I can say OutPath, and then I'm able to access whatever that would be.
So let's just go here.
The first thing we want to do, though, is actually make sure that we
actually have variables, which we don't, because of course,
we're not in Visual Studio Code. So, obviously, this function needs to be ran
after we've already executed all of the components previously.
So if I take all of this information here,
ComputerInfo, and go over here,
let's just paste all of this into here, you can see that
ComputerInfo is running, everything else you can see in the
loop. There's a bit of a problem there,
but that's okay, I'm not too worried about that, and then
let's do ComputerInfo should now contain, there we have it,
should now contain our HTML.
So let's go back.
What else do we need for our export? MemoryInfo. So let's make sure
that MemoryInfo is available, I'm just going to get rid of all this
extra, and we'll just see if MemoryInfo has been populated with
information, okay, it has two in HTML.
Let's look at BIOS info.
So, $BiosInfo, and sure enough, it's in HTML.
So, cross check we have everything available to us.
So, our function that we created was Export‑Csv‑Logs, so let's go over to here.
It's going to ask me for the output path.
I'm going to go ahead and do this log option here that's
available, paste that into there, and press Enter, and you can
see it generated Computer‑Information, Memory‑Information,
all these log files.
So let's go into the directory, and sure enough,
we can see that we have these files that have been created.
If I go into Computer‑Information,
you'll see that same information has been outputted as a table format as HTML.
Now, of course,
you may not want it to be a HTML format, so that's where you
would need to change the script slightly.
So if we go back to here, and in our Globo main one, that may be what
we're doing is we are exporting to this point here and then the
ConvertTo‑Html is done when we utilize that later.
So for example,
if I take this option, like so, go over here, let me just check
the MemoryInfo, which looks like HTML at the moment, if I run it
this way and then do MemoryInfo, it looks like that.
So, you may have to split out how you want that information to come
out because this looks better in a text file than it would if it
tried to render in a table in a document.
So, from a PowerShell perspective,
what you may end up doing is if we go somewhere like this,
let's say this was our command that we were using,
we'll just ignore this one for now, and let's take my ConvertTo‑Html Fragment,
what we would then do is come down to Memory Information here, and then we
would potentially wrap our syntax, like so. So that means that only when the
content sets are added to the new document do they get converted to HTML,
whereas when they are called normally, they would call in the normal structure
or the normal format.
So that's how we build the script, and that's how we execute the script, and
that's what the script looks like when it's been completed.