Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

HTML PowerShell report - error - reserved future us?

$
0
0

Hello,

I am trying to run an html report to pull quota data for file servers.  I keep getting an error about the < character being reserved for future use.  I've read about this, but thought if it was  in an HTML script format that it would work.  I've found other scripts online that use this and haven't found out if it's something with this script or that I'm doing wrong?

 

##——– Script starts here

 

$cssstyle = “<style>”

$cssstyle = $cssstyle + “BODY{background-color:white;}”

$cssstyle = $cssstyle + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”

$cssstyle = $cssstyle + “TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black;background-color:#C6D9F1;font-family:verdana;font-size:16px}”

$cssstyle = $cssstyle + “TD{border-width: 1px;padding: 4px;border-style: solid;border-color: black;background-color:white;font-family:verdana;font-size:14px}”

$cssstyle = $cssstyle + “</style>”

$content = “”

 

$serverarray = @{

Server1=”d:\public”;

SERVER2=”d:\myfolder”

}

$serverarray.keys | foreach {

$servername = $_

$mysession = new-pssession -ComputerName $servername

 

invoke-command -session $MySession -ScriptBlock {

 

function Get-FolderSize {

param ( [Parameter(Mandatory=$true)] [System.String]${Path} )

 

$objFSO = New-Object -com  Scripting.FileSystemObject

$folders = (dir $path | ? {$_.PSIsContainer -eq $True})

foreach ($folder in $folders)

{

$quotainfo = (dirquota quota list /path:$($folder.Fullname))

if ($quotainfo.length -eq 35 -or $quotainfo.length -eq 3) {

$folder | Add-Member -MemberType NoteProperty -Name “Quota” -Value (“NoQuota”)

$folder | Add-Member -MemberType NoteProperty -Name “SizeMB” -Value (($objFSO.GetFolder($folder.FullName).Size) / 1MB) -PassThru

}

else {

$folder | Add-Member -MemberType NoteProperty -Name “Quota” -Value (“Set”)

$folder | Add-Member -MemberType NoteProperty -Name “SizeMB” -Value (($objFSO.GetFolder($folder.FullName).Size) / 1MB) -PassThru

}

}

}

 

}

 

$content = “<H1> DATA FOR $($_.toupper())</H1>”

write-host “Calculating free space…”

$freespace = invoke-command -session $MySession -ScriptBlock {Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -computer localhost | Select SystemName,DeviceID,VolumeName,@{Name=”Size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}},@{Name=”Freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}}}

 

$content += ‘<H2>FREE SPACE INFORMATION</H2>’

$content += (($freespace | select @{name=”Partition”;expression={$_.DeviceID}},”Size(GB)”,”Freespace(GB)”) | ConvertTo-Html -Fragment)

$content +=’<p>&nbsp;</p>’

 

$serverarray.$_ | foreach {

write-host “Calculating folders size and quota …”

$folders = invoke-command -session $MySession -ScriptBlock {param($path) get-foldersize $path} -ArgumentList $_

 

$content += “<H2>TOP 10 LARGEST FOLDERS FOR $($_.toupper())</H2>”

$content += (($folders | sort -Property SizeMB -Descending | select fullname,@{n=’FolderSize(MB)’;e={“{0:N0}” -f $_.SizeMB}} | select -First 10) | ConvertTo-Html -Fragment)

$content +=’<p>&nbsp;</p>’

 

$content += “<H2>QUOTA INFORMATION FOR $($_.toupper())</H2>”

$content += (($folders | select FullName,Quota,@{n=’FolderSize(MB)’;e={“{0:N0}” -f $_.SizeMB}} | Where-Object {$_.quota -eq “NoQuota”}) | ConvertTo-Html -Fragment)

$content +=’<p>&nbsp;</p>’

 

}

write-host “Exporting report”

$exportfile = “d:\scripts\Reports\”+$servername+”.html”

write-host “Exporting report $exportfile”

ConvertTo-Html -Head $cssstyle -PostContent $content >  $exportfile

 

remove-pssession $mysession

}

## ——– Script ends here


Viewing all articles
Browse latest Browse all 6937

Trending Articles