Hi all,
Ignoring the SharePoint element of this, all I'm really trying to do is make the result display in the body of the email. it doesn't The attachment is fine, renders fine and pulls the CSS fine.
I have to assume that it is because I'm not really closing off the HTML anywhere, but not sure.....
Anyway, here's the code, sanitised slightly, but you get the idea:
Ignoring the SharePoint element of this, all I'm really trying to do is make the result display in the body of the email. it doesn't The attachment is fine, renders fine and pulls the CSS fine.
I have to assume that it is because I'm not really closing off the HTML anywhere, but not sure.....
Anyway, here's the code, sanitised slightly, but you get the idea:
PHP:
# Add SharePoint snap-in
Add-PSSnapin Microsoft.SharePoint.PowerShell
# Set Variables
$Today = Get-Date -Format "dd-MM-yyy_hh-mm-ss"
$OutputPath = "E:\SiteCollectionSize"
$OutputFileName = "SPSCsizes-$Today"
$OutputFile = "$OutputPath\$OutputFileName.html"
$RetentionTimeDays = "14"
#SMTP Settings
$smtpsettings = @{
To = "[email protected]"
From = "[email protected]"
Subject = "SharePoint Site Collection Sizes"
SmtpServer = "my.smtp.server"
}
#HTML and CSS Var
$style = "
<style>
body { font-family:verdana; background-color: #b0c4de; }
table { font-size: 0.7em; width: 100%; border-width: 1px; border-style: solid; border-color: #000; border-collapse: collapse; }
th { border-width: 1px; padding: 2px 6px 1px 6px; border-style: solid; border-color: #000; background-color: #778899; }
td { border-width: 1px; padding: 2px 6px 1px 6px; border-style: solid; border-color: #000; }
tr:nth-child(odd) { background-color: #d3d3d3; }
tr:nth-child(even) { background-color: #fff; }
h2 { clear: both; font-size: 0.9em; }
</style
"
# PowerShell Query for Site Collection Sizes
$query = Get-SPSiteAdministration -Limit All | select Url, @{label="GB";Expression={[System.Math]::Round($_.DiskUsed/1024MB, 0)}} | Sort-Object -Descending -Property "GB" | ConvertTo-Html -Head $style -PreContent '<h2>SharePoint Site Collection by Size</h2>' | Out-File $OutputFile
#Send email message
Send-MailMessage @smtpsettings -Attachments $OutputFile -BodyAsHtml $style -Priority Normal