Solved

Powershell - GCI output

Posted on 2008-09-29
4
852 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
}
1
 
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 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