Link to home
Start Free TrialLog in
Avatar of WeTi
WeTi

asked on

Export the write-output into the html rapport

Dear expert
Im trying to build a server rapport for uptime using the code below. In Powershell output, this code below work fine, now I want to convert the result into a html and show it there.
This is where I got my problem, it doesnt work as I want, I want it to show the write-output in the html file, anyone can help?
Thanks

function Get-SystemInfo 
{ 
$ServerNames = Get-Content c:\serverlistOP.txt
foreach($server in $ServerNames){
$system = Get-WmiObject win32_operatingsystem -ComputerName $server
$uptime = (Get-Date) - $system.ConvertToDateTime($system.LastBootUpTime)
Write-Output ("Server: " + $server)
Write-Output ("Last boot: " + $system.ConvertToDateTime($system.LastBootUpTime))
Write-Output ("Uptime: " + $uptime.Days + " Days " + $uptime.Hours + " Hours " + $uptime.Minutes + " Minutes") 
}}
Get-SystemInfo | convertto-html > C:\test\test.html

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WeTi
WeTi

ASKER

Error: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
the serverlistOP.txt look like this:
srv03
srv04
srv02
sql02
web01
Avatar of WeTi

ASKER

Thanks man works now after changed array string to ServerNames. Great help again odBA
Can't reproduce your error, try as I might. Did you change anything in the code I posted?
Avatar of WeTi

ASKER

Yes I changed the var name ComputerName to ServerNames, my misstake, now it works thanks again