VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

How to Print if there is any output for the command in HTML File instead of all?

Hi All,

I have got this html code from Hostile Coding and I have given my input to this to get my desired output.Below Script Works fine.

Problem here is when I am executing below Script I am getting output in HTML File with all details.

Example: If any VM is not connected to CD ROM then also in the output html file I am seeing heading as "CD-ROM Connected to VM"- Which I doesn't require as there is no such VM.

Is there any way that I can print only if the command has output in HTML File.

Please suggest on this.

$OutputPath=Get-Date -UFormat "C:\users\$env:username\desktop\Reports\ /%B /%Y-%b-%d @ %I-%M%p.html"

$Css="<style>

body {

    font-family: Verdana, sans-serif;

    font-size: 14px;

  color: #666666;

  background: #FEFEFE;

}

#title{

  color:#90B800;

  font-size: 30px;

  font-weight: bold;

  padding-top:25px;

  margin-left:35px;

  height: 50px;

}

#subtitle{

  font-size: 11px;

  margin-left:35px;

}

#main {

  position:relative;

  padding-top:10px;

  padding-left:10px;

  padding-bottom:10px;

  padding-right:10px;

}

#box1{

  position:absolute;

  background: #F8F8F8;

  border: 1px solid #DCDCDC;

  margin-left:10px;

  padding-top:10px;

  padding-left:10px;

  padding-bottom:10px;

  padding-right:10px;

}

#boxheader{

  font-family: Arial, sans-serif;

  padding: 5px 20px;

  position: relative;

  z-index: 20;

  display: block;

  height: 30px;

  color: #777;

  text-shadow: 1px 1px 1px rgba(255,255,255,0.8);

  line-height: 33px;

  font-size: 19px;

  background: #fff;

  background: -moz-linear-gradient(top, #ffffff 1%, #eaeaea 100%);

  background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffffff), color-stop(100%,#eaeaea));

  background: -webkit-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

  background: -o-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

  background: -ms-linear-gradient(top, #ffffff 1%,#eaeaea 100%);

  background: linear-gradient(top, #ffffff 1%,#eaeaea 100%);

  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eaeaea',GradientType=0 );

  box-shadow:

  0px 0px 0px 1px rgba(155,155,155,0.3),

  1px 0px 0px 0px rgba(255,255,255,0.9) inset,

  0px 2px 2px rgba(0,0,0,0.1);

}

table{

  width:100%;

  border-collapse:collapse;

}

table td, table th {

  border:1px solid #98bf21;

  padding:3px 7px 2px 7px;

}

table th {

  text-align:left;

  padding-top:5px;

  padding-bottom:4px;

  background-color:#90B800;

color:#fff;

}

table tr.alt td {

  color:#000;

  background-color:#EAF2D3;

}

</style>"

#These are divs declarations used to properly style HTML using previously defined CSS

$PageBoxOpener="<div id='box1'>"

$one="<div id='boxheader'>vCenter Services</div>"

$BoxContentOpener="<div id='boxcontent'>"

$PageBoxCloser="</div>"

$br="<br>"

$two="<div id='boxheader'>DataStore</div>"

$three="<div id='boxheader'>DataStore Mapped With Hosts</div>"

$four="<div id='boxheader'>VM's Located on Local Storage</div>"

$five="<div id='boxheader'>VM's in Inconsistent Folders</div>"

$six="<div id='boxheader'>SCSI Bus Sharing(Virtual) in VM's</div>"

$seven="<div id='boxheader'>CD-ROM Connected to VM</div>"

$eight ="<div id='boxheader'>ISO Mounted to VM</div>"

$nine ="<div id='boxheader'>Physical Nic Card Below 1GB</div>"

$ten ="<div id='boxheader'>Host Configuration Issues</div>"

#Get vCenter Service Info

$vcservice = Get-Service -ComputerName srti003a vpxd,vctomcat,VMWareCertificateService,VMwareDirectoryService,VMwareIdentityMgmtService,VMwareKdcService,vmwarelogbrowser,VMwareSTS,vimQueryService,vmware-network-coredump,vmware-network-coredump-webserver,vimPBSM,vmware-ufad-vci,RpcEptMapper,DcomLaunch,RpcSs,VMTools | where {$_.Status -ne "Running"} | Select-Object Name,DisplayName,Status | ConvertTo-HTML -Fragment

#Get DataStore Issue Info

$dc = get-datastore | where {$_.State -eq "Unavailable"} | select-object Name,State | ConvertTo-HTML -Fragment

#Get DataStore Issue Mapped with Hosts Info

$dci = get-datastore | where {$_.State -eq "Unavailable"} | select-object Name,State

$maph = Get-VMHost -Datastore $dci.name | select Name | ConvertTo-HTML -Fragment

#Get VM Located on Local Storage which are registered in Inventory

$vmls = Get-Datastore  | where{$_.Name -match "local|stor"} | Get-VM | Get-HardDisk | select @{N='Name';E={$_.Parent}},@{N='Filename';E={$_.Filename.split('/')[0]}} | ConvertTo-HTML -Fragment

#Get VM Name Mismatch in Inventory and Folder Path

$vmi = Get-View -ViewType VirtualMachine |

where{$_.Name -ne $_.Summary.Config.VMPathName.Split('/] ')[2]} |

select Name,@{N='Path';E={$_.Summary.Config.VMPathName.Split('/')[0]}} | ConvertTo-HTML -Fragment

#SCSI Bus Sharing in VM

#$phy = Get-Cluster | Get-VMHost | Get-VM | Get-ScsiController | Where-Object {$_.BusSharingMode -eq ‘Physical’} | Select {$_.Parent.Name}, {$_.Parent.Host}, BusSharingMode | Sort {$_.Parent.Host} | ConvertTo-HTML -Fragment

$vir = Get-Cluster | Get-VMHost | Get-VM | Get-ScsiController | Where-Object {$_.BusSharingMode -eq ‘Virtual’} | Select {$_.Parent.Name}, {$_.Parent.Host}, BusSharingMode | Sort {$_.Parent.Host} | ConvertTo-HTML -Fragment

#CD-ROM Connected to VM

$cd = get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name | ConvertTo-HTML -Fragment

#ISO Mounted to VM

$iso = get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }} | ConvertTo-HTML -Fragment

#Physical NIC Card Speed below 1GB list

$nic = Get-VMHostNetworkAdapter | Where{$_.BitRatePerSec -ne "0" -and $_.BitRatePerSec -ne "1000" -and $_.BitRatePerSec -ne "10000"} | Where{$_.Name -match "vmnic"} | select Name,VMHost |  ConvertTo-HTML -Fragment

#Host Configuration Issues

$hi = Get-VMHost | select @{N='HostName';E={$_.Name}},@{N='Message';E={$_.ExtensionData.ConfigIssue.FullFormattedMessage}} | where{$_.Message -match "[string]"} | ConvertTo-HTML -Fragment

#Create HTML report

#-Head parameter could be omitted if header is declared in body

ConvertTo-Html -Title "vCheck" -Head "<div id='title'>PowerCLI Reporting</div>$br<div id='subtitle'>Report generated: $(Get-Date)</div>

" -Body " $Css $PageBoxOpener $one $BoxContentOpener $vcservice $PageBoxCloser $br $two $BoxContentOpener $dc $PageBoxCloser $br $three $BoxContentOpener $maph $PageBoxCloser $four $BoxContentOpener $vmls $PageBoxCloser $five $BoxContentOpener $vmi $PageBoxCloser $six $BoxContentOpener $vir $PageBoxCloser $seven $BoxContentOpener $cd $PageBoxCloser $Eight $BoxContentOpener $iso $PageBoxCloser $Nine $BoxContentOpener $nic $PageBoxCloser $Ten $PageBoxOpener $hi $PageBoxCloser

" | Out-File -filepath $OutputPath

0 Kudos
20 Replies
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Thank you so much Lucd.

Thanks a lot. I got my desired result.

0 Kudos