Solved

Powershell - GCI output

Posted on 2008-09-29
4
802 Views
Last Modified: 2008-09-30
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
0
Comment
Question by:n0ch1ps
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22599615
Not sure why you would want to do this, but in powershell it would be like:

$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
}
0
 
LVL 5

Author Comment

by:n0ch1ps
ID: 22603391
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

0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 50 total points
ID: 22604607
Use ConvertTo-html and send html instead.
0
 
LVL 5

Author Comment

by:n0ch1ps
ID: 22604747
Thats the badger, thank you ;)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now