n0ch1ps
asked on
Powershell - GCI output
Im playing with the following script to find files older than 1 day.
$DateToCompare = (get-date).AddDays(-1)
$logFiles = get-childitem C:\logs -recurse | ? {$_.LastWriteTime -lt $DateToCompare}
foreach ($f in $logfiles){
Write-Host $f.name
}
I can send the results via email, however, I need the name and lastwritetime of each file on a new line in the variable sent to the email function. In vb it would be something like:
foreach f in fld.files
fileformat = fileformat &Â vbcrlf
next
SendMail fileformat
Anyone know how this is done in PS? Cheers J
$DateToCompare = (get-date).AddDays(-1)
$logFiles = get-childitem C:\logs -recurse | ? {$_.LastWriteTime -lt $DateToCompare}
foreach ($f in $logfiles){
Write-Host $f.name
}
I can send the results via email, however, I need the name and lastwritetime of each file on a new line in the variable sent to the email function. In vb it would be something like:
foreach f in fld.files
fileformat = fileformat &Â vbcrlf
next
SendMail fileformat
Anyone know how this is done in PS? Cheers J
ASKER
I've already said why, I need a variable to send to my mail sending function that formats the mail body properly I.E
ex2322323.log 28/09/2008 00:00:01
ex2322323.log 28/09/2008 00:00:01
ex2322323.log 28/09/2008 00:00:01
NOT
ex2322323.log 28/09/2008 00:00:01 ex23232323.log 28/09/2008 00:00:01 ex223322.log 28/09/2008 00:00:01
ex2322323.log 28/09/2008 00:00:01
ex2322323.log 28/09/2008 00:00:01
ex2322323.log 28/09/2008 00:00:01
NOT
ex2322323.log 28/09/2008 00:00:01 ex23232323.log 28/09/2008 00:00:01 ex223322.log 28/09/2008 00:00:01
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thats the badger, thank you ;)
$DateToCompare = (get-date).AddDays(-1)
$logFiles = get-childitem C:\logs -recurse | ? {$_.LastWriteTime -lt $DateToCompare}
foreach ($f in $logfiles){
Write-output $f.name
Write-output $f.LastWriteTime
}
or
$DateToCompare = (get-date).AddDays(-1)
$logFiles = get-childitem C:\logs -recurse | ? {$_.LastWriteTime -lt $DateToCompare}
foreach ($f in $logfiles){
"{0}`n{1}" -f $f.name,$f.LastWriteTime
}