Advertisement
david62277

PVS Doc Script

Oct 15th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Set-AlternatingRows {
  2.     <#
  3.     .SYNOPSIS
  4.         Simple function to alternate the row colors in an HTML table
  5.     .DESCRIPTION
  6.         This function accepts pipeline input from ConvertTo-HTML or any
  7.         string with HTML in it.  It will then search for <tr> and replace
  8.         it with <tr class=(something)>.  With the combination of CSS it
  9.         can set alternating colors on table rows.
  10.        
  11.         CSS requirements:
  12.         .odd  { background-color:#ffffff; }
  13.         .even { background-color:#dddddd; }
  14.        
  15.         Classnames can be anything and are configurable when executing the
  16.         function.  Colors can, of course, be set to your preference.
  17.        
  18.         This function does not add CSS to your report, so you must provide
  19.         the style sheet, typically part of the ConvertTo-HTML cmdlet using
  20.         the -Head parameter.
  21.     .PARAMETER Line
  22.         String containing the HTML line, typically piped in through the
  23.         pipeline.
  24.     .PARAMETER CSSEvenClass
  25.         Define which CSS class is your "even" row and color.
  26.     .PARAMETER CSSOddClass
  27.         Define which CSS class is your "odd" row and color.
  28.     .EXAMPLE $Report | ConvertTo-HTML -Head $Header | Set-AlternateRows -CSSEvenClass even -CSSOddClass odd | Out-File HTMLReport.html
  29.    
  30.         $Header can be defined with a here-string as:
  31.         $Header = @"
  32.         <style>
  33.         TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
  34.         TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
  35.         TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
  36.         .odd  { background-color:#ffffff; }
  37.         .even { background-color:#dddddd; }
  38.         </style>
  39.         "@
  40.        
  41.         This will produce a table with alternating white and grey rows.  Custom CSS
  42.         is defined in the $Header string and included with the table thanks to the -Head
  43.         parameter in ConvertTo-HTML.
  44.     .NOTES
  45.         Author:         Martin Pugh
  46.         Twitter:        @thesurlyadm1n
  47.         Spiceworks:     Martin9700
  48.         Blog:           www.thesurlyadmin.com
  49.        
  50.         Changelog:
  51.             1.1         Modified replace to include the <td> tag, as it was changing the class
  52.                         for the TH row as well.
  53.             1.0         Initial function release
  54.     .LINK
  55.         http://community.spiceworks.com/scripts/show/1745-set-alternatingrows-function-modify-your-html-table-to-have-alternating-row-colors
  56.     .LINK
  57.         http://thesurlyadmin.com/2013/01/21/how-to-create-html-reports/
  58.     #>
  59.     [CmdletBinding()]
  60.     Param(
  61.         [Parameter(Mandatory,ValueFromPipeline)]
  62.         [string]$Line,
  63.        
  64.         [Parameter(Mandatory)]
  65.         [string]$CSSEvenClass,
  66.        
  67.         [Parameter(Mandatory)]
  68.         [string]$CSSOddClass
  69.     )
  70.     Begin {
  71.         $ClassName = $CSSEvenClass
  72.     }
  73.     Process {
  74.         If ($Line.Contains("<tr><td>"))
  75.         {   $Line = $Line.Replace("<tr>","<tr class=""$ClassName"">")
  76.             If ($ClassName -eq $CSSEvenClass)
  77.             {   $ClassName = $CSSOddClass
  78.             }
  79.             Else
  80.             {   $ClassName = $CSSEvenClass
  81.             }
  82.         }
  83.         Return $Line
  84.     }
  85. }
  86. function ToObject {
  87.     param(
  88.      [Parameter(
  89.           Position=0,
  90.           Mandatory=$false,
  91.           ValueFromPipeline=$true,
  92.           ValueFromPipelineByPropertyName=$true)
  93.     ]
  94.     [Alias('Command')]
  95.     [string]$cmd
  96.     )
  97.  
  98.      $collection = @()
  99.      $item = $null
  100.  
  101.      switch -regex (Invoke-Expression $cmd)
  102.      {
  103.           "^Record\s#\d+$"
  104.           {
  105.                 if ($item) {$collection += $item}
  106.                 $item = New-Object System.Object
  107.           }
  108.           "^(?<name>\w+):\s(?<value>.*)"
  109.           {
  110.                 if ($Matches.Name -ne "Executing")
  111.                 {
  112.                      $item | Add-Member -Type NoteProperty -Name $Matches.Name -Value $Matches.Value
  113.                 }
  114.           }
  115.      }
  116.      if ($item) {$collection += $item}
  117.      return $collection
  118. }
  119. try {asnp mclipssnapin -ErrorAction Stop} catch {Write-Host "McliPSSnapIn required" -f Red;break}
  120. $a = @"
  121. <style>
  122. TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;width: 95%}
  123. TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
  124. TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
  125. .odd { background-color:#ffffff; }
  126. .even { background-color:#dddddd; }
  127. </style>
  128. "@
  129.  
  130. ###### edit the path of the $htm######
  131. $htm = "\\server\share\info.html"
  132. if (Test-Path $htm) {ri $htm -Force}
  133. ("mcli-get server" | ToObject).servername | %{
  134. "mcli-get serverstatus -p servername=$_" | ToObject | select @{n="PVS Server";e={$_.servername}},@{n="Status";e={if ($_.status -eq "1"){"Active"} else {"Inactive"}}},@{n="Connected Devices";e={$_.devicecount}}
  135. } | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
  136. "<br><br>" | Out-File $htm -Encoding ascii -Append
  137. "mcli-get diskinfo" | ToObject | select @{n="vDisk";e={$_.disklocatorname}},@{n="Active Devices";e={$_.devicecount}},@{n="High Availability";e={if ($_.haenabled -eq "1") {$true} else {$false}}},`
  138. @{n="Write Cache Type";e={if ($_.writecachetype -eq "0") {"Private/Maint"} elseif ($_.writecachetype -eq "7") {"Cache to PVS Server Persistent"} elseif ($_.writecachetype -eq "1") {"Cache to PVS Server"}`
  139. elseif ($_.writecachetype -eq "3") {"Cache to Device RAM"} elseif ($_.writecachetype -eq "8") {"Cache to Device Hard Disk Persistent"} elseif ($_.writecachetype -eq "9") {"Cache to RAM with Overflow to Disk"}`
  140. elseif ($_.writecachetype -eq "4") {"Cache on HDD"}}} | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
  141. "<br><br>" | Out-File $htm -Encoding ascii -Append
  142. "mcli-get diskinfo" | ToObject | select disklocatorname,sitename,storename | %{
  143. $disk = $_.disklocatorname
  144. $site = $_.sitename
  145. $store = $_.storename
  146. "mcli-get diskversion -p disklocatorname=$disk,sitename=$site,storename=$store" | ToObject | select @{n="Disk Name";e={$disk}},@{n="Version";e={$_.version}},`
  147. @{n="Disk Status";e={if ($_.goodinventorystatus -eq "0" -and $_.access -ne "1") {"Not Synced"} elseif ($_.access -ne "1") {"Synced"} elseif ($_.access -eq "1") {"Read/Write"}}}
  148. } | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
  149. "<br><br>" | Out-File $htm -Encoding ascii -Append
  150. "mcli-get farm" | ToObject | select @{n="Farm Name";e={$_.farmname}},@{n="License Server";e={$_.licenseserver}},@{n="License Server Port";e={$_.licenseserverport}},`
  151. @{n="Database Server Name";e={$_.databaseservername}},@{n="Database Instance Name";e={if ($_.databaseinstancename -ne "") {$_.databaseinstancename} else {"Default"}}},`
  152. @{n="Database Name";e={$_.databasename}},@{n="Offline DB Enabled";e={if ($_.offlinedatabasesupportenabled -eq "1") {$true} else {$false}}} | ConvertTo-Html -head $a | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $htm -Encoding ascii -Append
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement