[pre]
function Create-TableOfContents
{
[CmdletBinding()]
Param
(
Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$PathToArchive,
#Param2 help description
[parameter(Mandatory=$true,
Position=1)]
[string]$PathToTOC
)
Begin
{
}
Process
{
$Style=@"
tr.odd {background-color: pink;}
tr.even {background-color: lightblue;}
h1 {border:1px solid black;background-color:lightgreen;text-align:center;width:700px}
table {border:2px solid red;width:700px}
th,td {padding-left:10px;}
.ft {width:80px}
.fs {width:80px}
.dc {width:115px}
h4 {background-color:lightgreen;font-style:em;width:700px;}
"@
$i=0
$subpaths=(Get-ChildItem -Path $PathToArchive -Directory -Recurse | Select-Object -ExpandProperty fullname)
$subpaths | ForEach-Object -Process {
$test1=(Get-ChildItem -Path $_ -File);
$test2=(Get-ChildItem -Path $_ -Directory)
if (!$test1.Exists -and !$test2.exists){
Write-Host “There are no files or directories in $_ ,empty folder!.”
} elseif($test1.exists -and $test2.Exists){
$i++;
$glublist=New-Object -TypeName System.Collections.ArrayList;
Write-Host “files AND directories in $_ “, “File Block #$i”
foreach ($file in $test1){
if((Get-ItemProperty -Path $file.FullName).Attributes -band [io.fileattributes]::Archive -and (Get-ItemProperty -Path $file.FullName -Exclude partial))
{($glublist.add($file))
Write-Host “File Ready to Archive”;
} else {Write-Host “File Not Ready to Archive”}}
if($glublist.count -gt 0){
$DI=($test1.psparentpath -split(”::”))[1]
$params1=@{‘as’=‘table’
‘precontent’="
$DI
" 'oddrowcssclass'='odd' 'evenrowcssclass'='even' 'properties'=@{n='File Name';e={$_.basename}}, @{n='File Type';e={$_.extension};css={'ft'}}, @{n='Size (KB)';e={$_.length/1e3 -as [int]};css={'fs'}}, @{n='Date Created';e={($_.lastwritetime).toshortdatestring()};css={'dc'}}}$placeholder=($glublist | Sort-Object -Property extension,name | Select-Object -Property basename,extension,length,lastwritetime |
ConvertTo-EnhancedHTMLFragment @params1)
New-Variable -Name frag$i -Value ($placeholder)
}
} elseif($test2.exists){
Write-Host “Directories only in $"
} else{
$i++;
$gloplist=New-Object -TypeName System.Collections.ArrayList
Write-Host "Files only in $”, “File Block # $i”
foreach ($file in $test1){
if((Get-ItemProperty -Path $file.FullName).Attributes -band [io.fileattributes]::Archive -and (Get-ItemProperty -Path $file.FullName -Exclude partial))
{($gloplist.add($file))
Write-Host “Archive Bit Set”
} else {Write-Host “Archive Bit Cleared”}}
if($gloplist.count -gt 0){
$DI=($test1.psparentpath -split(“::”))[1]
$params1=@{‘as’=‘table’
‘precontent’="
$DI
" 'oddrowcssclass'='odd' 'evenrowcssclass'='even' 'properties'=@{n='File Name';e={$_.basename}}, @{n='File Type';e={$_.extension};css={'ft'}}, @{n='Size (KB)';e={$_.length/1e3 -as [int]};css={'fs'}}, @{n='Date Created';e={($_.lastwritetime).toshortdatestring()};css={'dc'}}}$placeholder=($gloplist | Sort-Object -Property extension,name | Select-Object -Property basename,extension,length,lastwritetime |
ConvertTo-EnhancedHTMLFragment @params1)
New-Variable -Name frag$i -Value ($placeholder)
}}
}
$params2=@{‘CssStyleSheet’=$Style
‘title’=“Table Of Contents”
‘precontent’="
Path To Archive Folder
" 'HTMLFragments'=@((Get-Variable frag* -ValueOnly))}ConvertTo-EnhancedHTML @params2 | Out-File $pathtoTOC
}}
[/pre]
Getting this to finally work was a real humpfest. It took several months, and I had to also take a class on HTML5 and CSS from EdX university…Really excellent, BTW. I would show some of the output, but I can’t get the clipboard to do a paste.
On the book I have a question. The code starts as follows:
.EXAMPLE
.\New HTMLSystemReport -ComputerName ONE,TWO`
-Path C:\Reports\
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true…
Shouldn’t there be a line just after the comment closure that says
Function verb-noun?