June 1, 2018 at 10:00 pm
I have this piece of code which is currently working but I an additional column added to the existing table and then emailed.
$Header = @"
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
"@
Get-ChildItem -Path \\nwh004\SQLBackups\Daily -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)}|ConvertTo-Html -Property FullName,Length,LastWriteTime -Head $Header |Out-File \\abcd\efgh\ijkl\files_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).'html'
It gives me a table formatted output.
But it is not displaying the Length(size) of the file.
How can add the length column to the existing table.
And how do I email this File_20180601.html ?
Thanks
June 4, 2018 at 2:08 pm
Use Select-Object to get the values. Not sure why, but this seems to work:
Get-ChildItem -Path "e:\Documents\" -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)}|Select-Object FullName, Length, LastWriteTime | ConvertTo-Html -Property FullName,Length,LastWriteTime -Head $Header |Out-File files_$((Get-Date).ToString('MM-dd-yyyy_hh-m')).'html'
You can also add to there WHERE-Object and use the $_.PSIsContainer -eq $false. Looks like null length folders are causing issues.
I'd make sure you use a variable for the path and days to add. Make this a useful, flexible script.
For email, check Send-MailMessage
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply