Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell - GCI output

Posted on 2008-09-29
4
Medium Priority
?
863 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 150 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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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