0

I'm stumped on this. I am making my way through a file share migration to SharePoint. There have been errors stating the "The item created time or modified time is not supported". No worries as I found a script to edit this in PowerShell:

cd "Directory"

Get-ChildItem -force | Select-Object Mode, Name, CreationTime, LastAccessTime, LastWriteTime | ft

$modifyfiles = Get-ChildItem -force | Where-Object {! $\_.PSIsContainer}
foreach($object in $modifyfiles)
{
$object.CreationTime=("1/3/2023 12:00:00")
$object.LastAccessTime=("1/3/2023 12:01:00")
$object.LastWritetime=("1/3/2023 12:02:00")
}

My question is how do I run this so I don't have to cd to each new directory every time. I have quite a few files in different folders that all need editing. I have the list of paths I need changed and I was hoping there would be a way to "pass" those paths in or somehow run this script in a loop.

IT GUY
  • 1

1 Answers1

1

Assuming your list of folders looks like this and can be placed in a seperate text file:

C:\folderpath\folder1
C:\folderpath\folder2
C:\folderpath\folder3

Then you could just do something like this:

get-content -Path "C:\folderpath\FileContainingFolderPaths.txt" | ForEach-Object {
    
    $folderpath = $_

    Get-ChildItem -Path $folderpath -force | Select-Object Mode, Name, CreationTime, LastAccessTime, LastWriteTime | ft

    $modifyfiles = Get-ChildItem -Path $folderpath -force | Where-Object {! $\_.PSIsContainer}
    foreach($object in $modifyfiles)
    {
        $object.CreationTime=("1/3/2023 12:00:00")
        $object.LastAccessTime=("1/3/2023 12:01:00")
        $object.LastWritetime=("1/3/2023 12:02:00")
    }

}

Also I'm gonna have to question you on the $\_.PSIsContainer, is that a mistake? I would think it should be $_.PSIsContainer instead?

djandDK
  • 23
  • 6
  • 1
    Just add switch `-File` to the Get-ChildItem cmdlet and remove that `| Where-Object {! $\_.PSIsContainer}` – Theo Jan 06 '23 at 13:59