This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.
We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
So you may show your code, explain what’s not working as expected or what errors you get and we might be able to help.
What do you mean?
And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
$date = get-date -Format D
<# This sets the title at the top of the log file #>
$logfile = "Log for: " + $date + "`n`n"
<# This sets the path and file name for the log file that will be exported at the end of the script #>
$logfilepath = "\\P1603\C$\Users\User\Desktop\LogPS\" + $date + " Deletion Log.txt"
<# The counter to keep track of how many files were copied #>
[int]$totalfilescopied = 0
<# The counter to keep track of how many files were deleted #>
[int]$totalfilesdeleted = 0
<# This is the command that gets all of the files (PDFs in my case) that are older than 90 days existing in that folder #>
$PDFsOlderThan90Days = Get-ChildItem '\\diskstation03\werkgroep\Grafisch Bedrijf\Rotatie\Origineel' *.pdf | Where-Object {$_.LastWriteTime -le (get-date).AddDays(-14)}
<# This is heart of the script that does all of the copying and deleting. You can see how it appends each file name to the log file by saying $logfile += .... #>
$PDFsOlderThan14Days | ForEach-Object {
copy $_.fullname '\\diskstation03\werkgroep\Grafisch Bedrijf\Rotatie\@FvdF\Origineel'
$logfile += "Copied file: " + $_.Name + " to backup directory `n"
$totalfilescopied = $totalfilescopied +1
remove-item $_.fullname
$logfile += "Deleted file: " + $_.Name + " from original directory `n"
$totalfilesdeleted = $totalfilesdeleted + 1
}
<# This writes to the log file the total number of files copied #>
$logfile += "`n`nYou copied a total of " + $totalfilescopied + " files to the OlderThan14 folder `n"
<# This writes to the log file the total number of files deleted #>
$logfile += "`n`nYou deleted a total of " + $totalfilesdeleted + " files from the original folder `n"
<# This is what seals the deal and writes the log file to a .txt file #>
$logfile | out-file $logfilepath
<# This is heart of the script that does all of the copying and deleting. You can see how it appends each file name to the log file by saying $logfile += … #>