Get-ChildItem -Path \abcd\efgh\ijkl -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-2)} | select name,lastWriteTime,Length
How do I add the filepath as an additional column?
How do I format the result into a HTML table and email it ?
Thanks
As for
How do I add the filepath as an additional column?
What file path?
You are using a one-liner and a path not storing the path to be used.
If you mean file path or full path of every file, just ask for that property.
gci *.* | gm
TypeName: System.IO.FileInfo
Name MemberType Definition
---- ---------- ----------
...
Directory Property System.IO.DirectoryInfo Directory {get;}
DirectoryName Property string DirectoryName {get;}
...
Extension Property string Extension {get;}
FullName Property string FullName {get;}
...
...
LastWriteTime Property datetime LastWriteTime {get;set;}
...
Length Property long Length {get;}
Name Property string Name {get;}
BaseName ScriptProperty System.Object BaseName {get=if ($this.Exte...
...
As for
How do I format the result into a HTML table and email it ?
Use the file cmdlets; i.e., Convertto-HTML and Send-MailMessage cmdlets.
For example:
Send HTML Formatted Emails using PowerShell.
Hi,Do you ever want to send an HTML formatted email using powershell.if yes then you can use this script.I am using this scrip very widely in setting up notifications. The best thing is that we can use this script with any other scripts. To know More info on this script click
'gallery.technet.microsoft.com/scriptcenter/Send-HTML-Formatted-email-26925a96'
I got to this point.
$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 \abcd\efgh\ijkl -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