I have been looking for help on this issue for a few hours with no luck. My script monitors a folder for files older than 12 minutes ending with '.tmp'. It then removes '.tmp'. This portion is working correctly.
I would like the script to output a text file containing the file name of the files that were renamed. With the script below, the text documents are empty.
#Computer name from Description
$ComputerName = Get-WmiObject -Class Win32_OperatingSystem | Select Description
$ComputerName = "$ComputerName".split("}")
$ComputerName = "$ComputerName".split("=") | Select-Object -Last 1
$ComputerName = "$ComputerName".split(" ") | Select-Object -First 1
#$ComputerName = $env:computername
Write-Host "This is the computer name: $ComputerName"
$c1Output = 'E:\' + $ComputerName + '\Capture One Session\Output\Market\'
get-childitem -Path "$c1Output" -Filter *.tmp |
where-object {$_.LastWriteTime -lt (get-date).AddMinutes(-12)} |
rename-item -newname { $_.name.substring(0,$_.name.length-4) }
out-file \\server\Report.txt
This should be easy to figure out, however I am still new to PowerShell.
Thanks!