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 15
ITguy565Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITguy565Author Commented:
Thank you once again sir.
0
ITguy565Author Commented:
Perfect Answer!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.