I am trying to use Don John’s Famous Enhanced HTML Report Script to pull some data out of Exchange 2013 Servers, I have created two functions to pull some basic data to test and i got this error message below. When i run the functions by itself they are working fine. I know the HTML requires string, does not like Arrays, Out-string does that but i still get the error below.
Error Message;
ConvertTo-EnhancedHTML : Cannot bind argument to parameter ‘HTMLFragments’ because it is an empty string.
At C:\Scripts\ExchReport.ps1:144 char:32
-
ConvertTo-EnhancedHTML @params | -
~~~~~~~- CategoryInfo : InvalidData: (
[ConvertTo-EnhancedHTML], ParameterBindingValidationException - FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,ConvertTo-EnhancedHTML
- CategoryInfo : InvalidData: (
ConvertTo-EnhancedHTML : Cannot bind argument to parameter ‘HTMLFragments’ because it is an empty string.
At C:\Scripts\ExchReport.ps1:144 char:32
-
ConvertTo-EnhancedHTML @params | -
~~~~~~~- CategoryInfo : InvalidData: (
[ConvertTo-EnhancedHTML], ParameterBindingValidationException - FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,ConvertTo-EnhancedHTML
- CategoryInfo : InvalidData: (
Script;
#requires -module EnhancedHTML2
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string]$ComputerName,
[Parameter(Mandatory=$True)]
[string]$Path
)
BEGIN {
Remove-Module EnhancedHTML2
Import-Module EnhancedHTML2
}
PROCESS {
$CSS = @"
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;
}
"@
function Get-BootInfo {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)][string]$ComputerName
)
$BootInfo = Get-CimInstance -ClassName win32_operatingsystem -ComputerName $ComputerName
$props = @{‘Server’=$bootInfo.CSName;
‘LastBootTime’=$bootInfo.LastBootUpTime}
New-Object -TypeName PSObject -Property $props
}
function Get-LargeEmail {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)][string]$ComputerName
)
$email = Get-MailboxStatistics -server $computerName |
sort-object -Property totalitemsize -des |
select-object Displayname, ItemCount, totalItemSize -first 10
$props = @{'User'=$email.Displayname;
'ItemCount'=$email.ItemCount;
'Mailbox Size'=$email.totalItemSize;
}
New-Object -TypeName PSObject -Property $props
}
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
}
if ($everything_ok) {
$filepath = Join-Path -Path $Path -ChildPath "$computer.html"
$params = @{'As'='Table';
'PreContent'='Server UP Time'}
$html_BootInfo = Get-BootInfo -ComputerName $computer |
Out-String |
ConvertTo-EnhancedHTMLFragment @params
$params = @{'As'='Table';
'PreContent'='Largest Email Users'}
$html_email = Get-LargeEmail -ComputerName $computer |
Out-String |
ConvertTo-EnhancedHTMLFragment @params
$params = @{'CssStyleSheet'=$style;
'Title'="System Report for $computer";
'PreContent'="System Report for $computer";
'HTMLFragments'=@($html_BootInf,$html_email);
'jQueryDataTableUri'='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.3/jquery.dataTables.min.js';
'jQueryUri'='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js'}
ConvertTo-EnhancedHTML @params |
Out-File -FilePath $filepath
}
}
}