Solved

Powershell output to HTML

Posted on 2016-10-27
1
72 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 500 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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

717 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