Hello All
First time I’m posting as I’ve become quite stuck on a script I’m creating using Dons ‘Convertto-EnhancedHTML’ function.
Any help would be greatly appreciated …
I’ve basically created a script that reads in a load of objects and pipes them out to a webpage using the ‘Convertto-EnhancedHTML’ advanced function.
The script is shown below and consists of a module file (which has all the advanced functions) that is called from the main script file.
The styling of the webpage is done via a css file which is also working fine. There are a lot more fragments in total but i’ve purposely not shown them
due to ease of readability.
PROBLEM: The problem I’m experiencing is when my Get-OsinfoVminfo function returns NOTHING (i.e. no objects) It messes up the entry on the
outputted webpage, so I would prefer it not to be outputted. Hence, I’ve been trying to figure out a way that if NO objects are
outputted then that fragment does not get added to my list of fragments …
Make sense ???
The code (which I’ve shown below) shows the basic configuation script and my functions sit in another PSM1 module file. (not added).
As I have mentioned it works great, just want to figure this ‘quirk’ out.
As usual any help would be GREATLY appreciated. Many thanks in advance
Controller Script - to be used in conjunction with ‘Advanced functions’
[CmdletBinding()]
PARAM(
[Parameter(Mandatory=$true,
Position=0,
HelpMessage = “Please enter a Servername”)]
[ValidateNotNullOrEmpty()]
[String]$computerName
)
BEGIN{
$style = (Get-content ‘C:\css\style.css’)
Get-Module OSTools | Out-Null
} # Begin
PROCESS{
Foreach ($computer in $computername) {
Write-Verbose $VC
$frag12 = Get-OsinfoVMInfo -VCName $computer | where { $_.name -ne (((($_.vmpathname).Split(']')[1]).Split('/'))[0].TrimStart(' '))} | Select Name,vmpathname |
ConvertTo-EnhancedHTMLFragment -TableCssID IFolders_TCID `
-DivCssID IFolders_DCID `
-DivCssClass IFolders_DCC `
-TableCssClass IFolders_TCC `
-As Table `
-Properties Name,vmpathname `
-MakeHiddenSection `
-MakeTableDynamic `
-Precontent 'Inconsistent Folders' | Out-String
$frag13 = Get-OsinfoVMInfo -VCName $computer | where {$_.'Consolidation Needed' -eq $true} | Select Name, 'Consolidation Needed' |
ConvertTo-EnhancedHTMLFragment -TableCssID Consolidation_Needed_TCID `
-DivCssID Consolidation_Needed_DCID `
-DivCssClass Consolidation_Needed_DCC `
-TableCssClass Consolidation_Needed_TCC `
-As Table `
-Properties Name,'Consolidation Needed' `
-MakeHiddenSection `
-MakeTableDynamic `
-Precontent 'Consolidation Required' | Out-String
$frag14 = Get-OsinfoVMInfo -VCName $computer | where {($_.'NIC Connected' -ne $true) -or ($_.'NIC Start' -ne $true)} | Select Name, 'NIC Connected','NIC Start' |
ConvertTo-EnhancedHTMLFragment -TableCssID NIC_Connected_TCID `
-DivCssID NIC_Connected_DCID `
-DivCssClass NIC_Connected_DCC `
-TableCssClass NIC_Connected_TCC `
-As Table `
-Properties Name,'NIC Connected','NIC Start' `
-MakeHiddenSection `
-MakeTableDynamic `
-Precontent 'NIC State' | Out-String
$frag15 = Get-OsinfoVMInfo -VCName $computer | where {($_.'Inaccessible/Invalid VM' -eq 'Invalid') -or ($_.'Inaccessible/Invalid VM' -eq 'Inaccessible')} | Select Name, 'Inaccessible/Invalid VM' |
ConvertTo-EnhancedHTMLFragment -TableCssID InvalidVMs_TCID `
-DivCssID InvalidVMs_DCID `
-DivCssClass InvalidVMs_DCC `
-TableCssClass InvalidVMs_TCC `
-As Table `
-Properties Name,'Inaccessible/Invalid VM' `
-MakeHiddenSection `
-MakeTableDynamic `
-Precontent 'Inaccessible VMs' | Out-String
$path = Join-Path -Path 'C:\temp' -ChildPath ("$VC" + "_" + "$(((Get-date).ToShortDateString()) -replace '/','')" + ".html")
ConvertTo-EnhancedHTML -Title "Morning Check Report for $computer" `
-PreContent "Morning Report: $(($VC).ToUpper())" `
-HTMLFragments $frag1,$frag2,$frag3,$frag4,$frag5,$frag6,$frag7,$frag8,$frag9,$frag10,$frag11,$frag12,$frag13,$frag14,$frag15 `
-PostContent "Time Retrieved $(Get-Date)" `
-CssStyleSheet $style |
Out-File $path -Encoding ascii
} #foreach
} # Process
END{} # End