• Complain

it-ebooks - Creating HTML Reports in PowerShell

Here you can read online it-ebooks - Creating HTML Reports in PowerShell full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: iBooker it-ebooks, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

it-ebooks Creating HTML Reports in PowerShell
  • Book:
    Creating HTML Reports in PowerShell
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2018
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Creating HTML Reports in PowerShell: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Creating HTML Reports in PowerShell" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote Creating HTML Reports in PowerShell? Find out the surname, the name of the author of the book and a list of all author's works by series.

Creating HTML Reports in PowerShell — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Creating HTML Reports in PowerShell" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Table of Contents
Building the HTML
Building the HTML

I'm going to abandon the native ConvertTo-HTML cmdlet that I've discussed so far, Instead, I'm going to ask you to use the EnhancedHTML2 module that comes with this ebook. Note that, as of October 2013, this is a new version of the module - it's simpler than the EnhancedHTML module I introduced with the original edition of this book.

Let's start with the script that actually uses the module. It's included with this book as EnhancedHTML2-Demo.ps1, so herein I'm going to paste the whole thing, and then insert explanations about what each bit does. Note that I can't control how the code will line-wrap in an e-reader, so it might look wacky.

#requires -module EnhancedHTML2[CmdletBinding()]param( [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string[]]$ComputerName, [Parameter(Mandatory=$True)] [string]$Path)

The above section tells us that this is an "advanced script," meaning it uses PowerShell's cmdlet binding. You can specify one or more computer names to report from, and you must specify a folder path (not a filename) in which to store the final reports.

BEGIN { Remove-Module EnhancedHTML2 Import-Module EnhancedHTML2}

The BEGIN block can technically be removed. I use this demo to test the module, so it's important that it unload any old version from memory and then re-load the revised version. In production you don't need to do the removal. In fact, PowerShell v3 and later won't require the import, either, if the module is properly located in \Documents\WindowsPowerShell\Modules\EnhancedHTML2.

PROCESS {$style = @"body { color:#333333; font-family:Calibri,Tahoma; font-size: 10pt;}h1 { text-align:center;}h2 { border-top:1px solid #666666;}th { font-weight:bold; color:#eeeeee; background-color:#333333; cursor:pointer;}.odd { background-color:#ffffff; }.even { background-color:#dddddd; }.paginate_enabled_next, .paginate_enabled_previous { cursor:pointer; border:1px solid #222222; background-color:#dddddd; padding:2px; margin:4px; border-radius:2px;}.paginate_disabled_previous, .paginate_disabled_next { color:#666666; cursor:pointer; background-color:#dddddd; padding:2px; margin:4px; border-radius:2px;}.dataTables_info { margin-bottom:4px; }.sectionheader { cursor:pointer; }.sectionheader:hover { color:red; }.grid { width:100% }.red { color:red; font-weight:bold;} "@

That's called a Cascading Style Sheet, or CSS. There are a few cool things to pull out from this:

I've jammed the entire

section into a here-string, and stored that in the variable $style. That'll make it easy to refer to this later.

Notice that I've defined styling for several HTML tags, such as H1, H2, BODY, and TH. Those style definitions list the tag name without a preceding period or hash sign. Inside curly brackets, you define the style elements you care about, such as font size, text alignment, and so on. Tags like H1 and H2 already have predefined styles set by your browser, like their font size; anything you put in the CSS will override the browser defaults.

Styles also inherit. The entire body of the HTML page is contained within the

tags, so whatever you assign to the BODY tag in the CSS will also apply to everything in the page. My body sets a font family and a font color; H1 and H2 tags will use the same font and color.

You'll also see style definitions preceded by a period. Those are called class styles, and I made them up out of thin air. These are sort of reusable style templates that can be applied to any element within the page. The ".paginate" ones are actually used by the JavaScript I use to create dynamic tables; I didn't like the way its Prev/Next buttons looked out of the box, so I modified my CSS to apply different styles.

Pay close attention to .odd, .even, and .red in the CSS. I totally made those up, and you'll see me use them in a bit.

function Get-InfoOS { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $os = Get-WmiObject -class Win32_OperatingSystem -ComputerName $ComputerName $props = @{'OSVersion'=$os.version 'SPVersion'=$os.servicepackmajorversion; 'OSBuild'=$os.buildnumber} New-Object -TypeName PSObject -Property $props}function Get-InfoCompSystem { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $cs = Get-WmiObject -class Win32_ComputerSystem -ComputerName $ComputerName $props = @{'Model'=$cs.model; 'Manufacturer'=$cs.manufacturer; 'RAM (GB)'="{0:N2}" -f ($cs.totalphysicalmemory / 1GB); 'Sockets'=$cs.numberofprocessors; 'Cores'=$cs.numberoflogicalprocessors} New-Object -TypeName PSObject -Property $props}function Get-InfoBadService { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $svcs = Get-WmiObject -class Win32_Service -ComputerName $ComputerName ` -Filter "StartMode='Auto' AND State<>'Running'" foreach ($svc in $svcs) { $props = @{'ServiceName'=$svc.name; 'LogonAccount'=$svc.startname; 'DisplayName'=$svc.displayname} New-Object -TypeName PSObject -Property $props }}function Get-InfoProc { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $procs = Get-WmiObject -class Win32_Process -ComputerName $ComputerName foreach ($proc in $procs) { $props = @{'ProcName'=$proc.name; 'Executable'=$proc.ExecutablePath} New-Object -TypeName PSObject -Property $props }}function Get-InfoNIC { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $nics = Get-WmiObject -class Win32_NetworkAdapter -ComputerName $ComputerName ` -Filter "PhysicalAdapter=True" foreach ($nic in $nics) { $props = @{'NICName'=$nic.servicename; 'Speed'=$nic.speed / 1MB -as [int]; 'Manufacturer'=$nic.manufacturer; 'MACAddress'=$nic.macaddress} New-Object -TypeName PSObject -Property $props }}function Get-InfoDisk { [CmdletBinding()] param( [Parameter(Mandatory=$True)][string]$ComputerName ) $drives = Get-WmiObject -class Win32_LogicalDisk -ComputerName $ComputerName ` -Filter "DriveType=3" foreach ($drive in $drives) { $props = @{'Drive'=$drive.DeviceID; 'Size'=$drive.size / 1GB -as [int]; 'Free'="{0:N2}" -f ($drive.freespace / 1GB); 'FreePct'=$drive.freespace / $drive.size * 100 -as [int]} New-Object -TypeName PSObject -Property $props }}

The preceding six functions do nothing but retrieve data from a single computer (notice that their -ComputerName parameter is defined as [string], accepting one value, rather than [string[]] which would accept multiples). If you can't figure out how these work... you probably need to step back a bit!

For formatting purposes in this book, you're seeing me use the back tick character (like after -ComputerName $ComputerName). That escapes the carriage return right after it, turning it into a kind of line-continuation character. I point it out because it's easy to miss, being such a tiny character.

foreach ($computer in $computername) { try { $everything_ok = $true Write-Verbose "Checking connectivity to $computer" Get-WmiObject -class Win32_BIOS -ComputerName $Computer -EA Stop | Out-Null } catch { Write-Warning "$computer failed" $everything_ok = $false }

The above kicks off the main body of my demo script. It's taking whatever computer names were passed to the script's -ComputerName parameter, and going through them one at a time. It's making a call to Get-WmiObject as a test - if this fails, I don't want to do anything with the current computer name at all. The remainder of the script only runs if that WMI call succeeds.

if ($everything_ok) { $filepath = Join-Path -Path $Path -ChildPath "$computer.html"

Remember that this script's other parameter is -Path. I'm using Join-Path

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Creating HTML Reports in PowerShell»

Look at similar books to Creating HTML Reports in PowerShell. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Creating HTML Reports in PowerShell»

Discussion, reviews of the book Creating HTML Reports in PowerShell and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.