Powershell script to Create and Export Table in HTML format

Experts,

I need a script that can do the following :

use the output from the following code on a List of computers
$computers | Get-ADcomputer -Properties DNSHostName,CreatetimeStamp,CanonicalName,ObjectGUID,objectSid,DistinguishedName,IPV4Address,OperatingSystem,OperatingSystemVersion |select DNSHostName,CreatetimeStamp,CanonicalName,ObjectGUID,objectSid,DistinguishedName,IPV4Address,OperatingSystem,OperatingSystemVersion

Open in new window


Output the results Per Computer

DNSHostName : Computer 1.mydomain.com
CreateTimeStamp :
CononicalName :
ObjectGuid :
objectSid :
DistinguishedName :
IPV4Address :
OperatingSystem :
OperatingSystemVersion :

Take the results per computer and create an HTML table with the same line format as is show above. and save it to a file called "ComputerName_Table1.HTML"
DNSHostName : Computer 1.mydomain.com
CreateTimeStamp :
CononicalName :
ObjectGuid :
objectSid :
DistinguishedName :
IPV4Address :
OperatingSystem :
OperatingSystemVersion :


NOT:

DNSHOSTNAME, CreateTimeStamp, CanonicalName ........

i know I can export the code and get the format like this DNSHOSTNAME, CreateTimeStamp, CanonicalName ........
LVL 13
ITguy565Asked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
ConvertTo-Html has the "-As List" argument, which will provide output in list format.
That should do the trick:
$outFolder = 'C:\Temp\Html'
$computers = 'server1', 'server2'
$properties = 'DNSHostName', 'CreatetimeStamp', 'CanonicalName', 'ObjectGUID', 'objectSid', 'DistinguishedName', 'IPV4Address', 'OperatingSystem', 'OperatingSystemVersion'
$htmlHead = @'
<style>
	table{border-width:1px; border-style:solid; border-color:black;}
	th{border-width:1px; padding:1px; border-style:solid; border-color:black;}
	td{border-width:1px; padding:1px; border-style:solid; border-color:black;}
</style>
'@
ForEach ($computer In $computers) {
	Get-ADcomputer -Identity $computer -Property $properties |
		Select-Object -Property $properties | 
		ConvertTo-Html -As List -Head $htmlHead |
		Set-Content "$($outFolder)\$($computer)_Table1.html"
}

Open in new window

2
 
ITguy565Author Commented:
Thank you once again sir.
0
 
ITguy565Author Commented:
Perfect Answer!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.