good afternoon
I recently tried to adapt this powershell script (from "Hey, Scripting Guy! Blog") to change the timestamps file (CreationTime, LastAccessTime and LastWriteTime) of one file instead of the files in the folder. But I had problems getting it to work with the changes I made.
The original script looks like this:
Set-FileTimeStamps function Function Set-FileTimeStamps { Param ( [Parameter(mandatory=$true)] [string[]]$path, [datetime]$date = (Get-Date)) Get-ChildItem -Path $path | ForEach-Object { $_.CreationTime = $date $_.LastAccessTime = $date $_.LastWriteTime = $date } }
And modified:
Function Set-FileTimeStamps { Param ( [Parameter(mandatory=$true)] [string]$file, [datetime]$date = (Get-Date)) $file.CreationTime = $date $file.LastAccessTime = $date $file.LastWriteTime = $date }
When I try to run the script, it causes the following error:
Property 'CreationTime' cannot be found on this object; make sure it exists and is settable. At C:\Users\Anton\Documents\WindowsPowerShell\Modules\Set-FileTimeStamps\Set-FileTimeStamps.psm1:7 char:11 + $file. <<<< CreationTime = $date + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException
So, it is not clear to me where I fail to modify the original script, and I would be grateful if someone could point me in the right direction.
Thanks in advance.
source share