function Get-FilesReadyToArchive { [CmdletBinding()] Param ( # Determine path to head directory of archive tree [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$PathToArchive ) Begin { } Process{$AFiles=Get-ChildItem -Path $PathToArchive -Recurse -File foreach($file in $Afiles){ if((Get-ItemProperty -Path $file.FullName).Attributes -band [io.fileattributes]::archive -and (Get-ItemProperty -Path $file.FullName -Exclude *partial*)) {$hash=[ordered]@{'Directory'=($file).Directory 'File Name'=($file).basename 'File Type'=($file).Extension 'File Size (KB)'=($file).Length/1e3 -as [int] 'Date Created'=($file).LastWriteTime} $glob=New-Object -TypeName PSObject -Property $hash Write-Output $glob} } }} function Save-TableOfContents { [CmdletBinding()] [OutputType([int])] Param ( # Param1 help description [Parameter(Mandatory=$true,HelpMessage="Default location is C:\MyArchive.html", Position=0)] [string]$PathToContents ) Begin { } Process { Get-FilesReadyToArchive | Sort-Object -Property directory | ConvertTo-Html -Property 'File Name', 'File Type','File Size (KB)','Date Created' -Head 'Document created on' -PreContent (Get-Date) > $PathToContents } End { } }
Powershell version 5.0; OS Windows 7 Home Premium
I have written a module that can copy all files in a folder with the archive bit set to archival storage. One annoying problem is when I use the cmdlet that saves a Table of Contents in an HTML file, the file listing is random. Also, if I run it twice, I get a different order for the listing. Is there any way to achieve a listing that is in alphabetical order? Shown are the two cmdlets involved.