Log actions to file | how to? RRS feed

  • Question

  • Hello - I need help in getting this script improved - this script will search for a file on remote machines and delete it.

    I would like to see the files listed on screen and see a line about them being deleted.

    $date = Get-Date -Format dd-MMM-yyyy
    $time = Get-Date -Format "hh-mm-ss tt"
    $Computer = Get-Content D:\Script\servers.txt
    Start-Transcript -Path C:\Windows\Temp\$LogDate.log
    foreach ($item in $items)
        $Search = Get-ChildItem "\\$item\C$\users\*\AppData\Local\Microsoft\Windows" -Filter wpad*.dat -Recurse -Force -Verbose -ErrorAction SilentlyContinue 
        $Search | Remove-Item 
    $Search  >> D:\Script\filefound_$date_$time.log

    How can I create a log for all files found from Get-childItem 

    How can I create a log for all files delete from Remote-Item

    How can I output to screen all of the above and to a log file which will append all the computers that I target?



    Friday, July 14, 2017 5:26 PM

All replies

  •  $Search | Remove-Item-PassThru | Export-Csv files.csv


    Friday, July 14, 2017 5:32 PM
  • Always you. :) Thanks. That resolved the matter for the remove-item How can I see on screen the results of get-childitem? As in the script finds a file and outputs to screen (and log file) M


    Friday, July 14, 2017 5:57 PM
  • $Search | Remove-Item-PassThru -Verbose | Export-Csv files.csv

    Try using help to learn how to use the CmdLets.


    Friday, July 14, 2017 6:05 PM
  • Can't find that command to be available: Remove-Item-PassThru -Verbose

    Which PSVersion are we talking about here?



    Saturday, July 15, 2017 11:45 AM
  • This works:

    $Search | Remove-Item -Verbose


    Saturday, July 15, 2017 11:48 AM