'I am on Powershell 5.1 I am looping over a directory and I need to 275 days to the CreationTime and LastWriteTime

I need to add 275 days to the Each file in the directories $object.CreationTime and $object.LastWriteTime. In the same format as this 10 November 2016 12:00:00. I will take that variable and remove the strings being passed in now.

$files =  Get-ChildItem -force | Where-Object {! $_.PSIsContainer} 
foreach($object in $files)
{
     $object.CreationTime=("10 November 2016 12:00:00")
     $object.LastWriteTime=("10 November 2016 12:00:00")
}


Solution 1:[1]

If I understand correctly this may work...

$newDateString = '10 November 2016 12:00:00';

In loop:

$object.CreationTime = Get-Date($newDateString);
$object.LastWriteTime = Get-Date($newDateString);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tanstaafl