?
Solved

Powershell output to HTML

Posted on 2016-10-27
1
Medium Priority
?
76 Views
Last Modified: 2016-10-27
I have the below script, it converts to HTML and usually emails (i have it commented out) but this is in a pci zone so no access to email.  Is there a way i can save it to a UNC path?

$servers = Get-ADComputer -SearchBase "OU=Servers,DC=Enterprise-1,DC=local" -Filter *
$servers += Get-ADComputer -SearchBase "OU=Domain Controllers,DC=Enterprise-1,DC=local" -Filter *

$data = @()

foreach ($i in $servers){

    $server = $i.name
	$server

    if (Test-Connection -ComputerName $server -Count 1 -ErrorAction SilentlyContinue){ 

        $wmi = gwmi Win32_OperatingSystem -ComputerName $server
        $bootTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime)
        $uptime = New-TimeSpan -Start $bootTime -End (Get-Date)
        $upDays = $uptime.Days
        $upHours = $uptime.Hours
        $upMin = $uptime.Minutes
        $upSecs = $uptime.Seconds

        $object = New-Object –TypeName PSObject
        $object | Add-Member –MemberType NoteProperty –Name Server –Value $server
        $object | Add-Member –MemberType NoteProperty –Name Days –Value $upDays
        $object | Add-Member –MemberType NoteProperty –Name Hours –Value $upHours
        $object | Add-Member –MemberType NoteProperty –Name Minutes –Value $upMin
        $object | Add-Member –MemberType NoteProperty –Name Seconds –Value $upSecs

        #Write-Output $object
        $data += $object

        #Write-Output "$server - Uptime: $($uptime.Days):$($uptime.Hours):$($uptime.Minutes):$($uptime.Seconds)"

    }
    else {

        $object = New-Object –TypeName PSObject
        $object | Add-Member –MemberType NoteProperty –Name Server –Value $server
        $object | Add-Member –MemberType NoteProperty –Name Days –Value "null"
        $object | Add-Member –MemberType NoteProperty –Name Hours –Value "null"
        $object | Add-Member –MemberType NoteProperty –Name Minutes –Value "null"
        $object | Add-Member –MemberType NoteProperty –Name Seconds –Value "null"

        #Write-Output $object
        $data += $object

    }
}
#$mydata = $data | sort Days -Descending | ft -auto
#$mydata = $data | sort Days -Descending | ft -auto | Out-String
$data = $data | Sort-Object Days -Descending | ConvertTo-Html
#Send-MailMessage -To "" -Subject "[Info] Server Uptimes" -From "" -Body "$data" -BodyAsHtml -SmtpServer ""

Open in new window

0
Comment
Question by:leadtheway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 41862123
You can use Out-File to save the file.. Example..

$data | Sort-Object Days -Descending | ConvertTo-Html | Out-File "\\ServerA\Reports\Report.htm"

Open in new window

Or after line 50 add..
$data | Out-File "\\ServerA\Reports\Report.htm"

Open in new window

PS : Make sure the share is accessible from your server where you run the script..
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question