none
Powershell Script RRS feed

  • Question

  • Hi

    I need some help please with a powershell script that will output to HTML format

    I have come upon some scripts on the internet that does help a bit but I need to query specific machines every 10 minutes for % CPU usage - write the information per system into a single line for each computer - in html - then sample that every hour for an average CPU% used per hour repeated over a 4hour cycle

    below is a sample of the scripts that I have

    $ServerListFile="C:\PowerShell\computerlist.txt" 

    $ServerList

    =Get-Content$ServerListFile-ErrorActionSilentlyContinue

    $Result

    =@()

    ForEach

    ($computernamein$ServerList)

    {

    $Counters

    =@(

    'processor(_total)\% processor time'

    start-sleep-s15 #I am using 15 seconds just as a test but in the final it will be executed every 10 minutes

    'memory\% committed bytes in use' #this value needs to be replaced by %processor for each computer sampled every 10 minutes

    start-sleep-s15

    'memory\cache faults/sec' #this value needs to be replaced by %processor for each computer sampled every 10 minutes

    start-sleep-s15

    'physicaldisk(_total)\% disk time' #this value needs to be replaced by %processor for each computer sampled every 10 minutes

    start-sleep-s15

    'physicaldisk(_total)\current disk queue length' #this value needs to be replaced by %processor for each computer sampled every 10 minutes

    )


    Get-Counter

    -computername$computername-Counter$Counters-MaxSamples1|ForEach{

       

    $_.CounterSamples |ForEach{

           

    [pscustomobject]@{

                TimeStamp

    =$_.TimeStamp

                Path

    =$_.Path

                Value

    =$_.CookedValue

            }

        }

    }

    #| Export-Csv -Path PerfMonCounters.csv -NoTypeInformation


    $Outputreport

    |out-file"C:\PowerShell\Test3.htm"# -Append


    }

    current output

    should look like something like this


    • Edited by MikeFGR Tuesday, November 20, 2018 11:00 AM TEST
    Tuesday, November 20, 2018 11:00 AM

Answers

  • Hope this helps a bit .....

    # Output File
    $strOutFile = "C:\temp\snapshot_list.htm"
    
    # HTML/CSS style for the output file
    $head = "<style>"
    $head = $head + "BODY{background-color:white;}"
    $head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Yellow}"
    $head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black}"
    $head = $head + "</style>"
    
    $Users= Get-ADcomputer -Properties * -filter * | Select Name, OperatingSystem
    
    
    $Users | Sort-Object Size | ConvertTo-HTML -Head $head | Out-File $strOutFile

    • Proposed as answer by ComputerScott Thursday, November 29, 2018 11:08 PM
    • Marked as answer by MikeFGR Friday, November 30, 2018 5:12 AM
    Wednesday, November 28, 2018 11:10 PM

All replies

  • Please do not post pre-colorized code. Edit your original post and use the code posting tool provided on the toolbar of the post editor. Thanks.

    You should also read this first: This forum is for scripting questions rather than script requests.

    Also find scripts here: PowerShell Gallery or here: TechNet Gallery - resources for IT professionals.

    Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell.

    Script requests: Microsoft Technet Script Center - Requests.

    Regardless of all that: we do not customize scripts found on the internet on request. Ask the author of the script for help with it.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Tuesday, November 20, 2018 11:22 AM
    Tuesday, November 20, 2018 11:19 AM
  • Hope this helps a bit .....

    # Output File
    $strOutFile = "C:\temp\snapshot_list.htm"
    
    # HTML/CSS style for the output file
    $head = "<style>"
    $head = $head + "BODY{background-color:white;}"
    $head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Yellow}"
    $head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black}"
    $head = $head + "</style>"
    
    $Users= Get-ADcomputer -Properties * -filter * | Select Name, OperatingSystem
    
    
    $Users | Sort-Object Size | ConvertTo-HTML -Head $head | Out-File $strOutFile

    • Proposed as answer by ComputerScott Thursday, November 29, 2018 11:08 PM
    • Marked as answer by MikeFGR Friday, November 30, 2018 5:12 AM
    Wednesday, November 28, 2018 11:10 PM
  • Hi ComputerScott

    thank you I will go and apply the principles that you have shared here on how to create the tables and rows within the HTML output file

    thank you

    Thursday, November 29, 2018 4:07 AM
  • Please mark as answered if it works out for you 
    Thursday, November 29, 2018 11:08 PM