0

I have several text files and I want to change the creation date of these files. I am running on several problems so I would appreciate advice for my case.

First I found this solution to change the creation date of one file. It involves running powershell (windows 10) with

 (Get-Item test2.txt).creationtime=$(Get-Date "1/2/2016 12
:34 am")

It works. So then I have two issues. First, how to do this to a thousand files? It has to be automated or it would take too much time.

The second issue though is much more important. Once I change the creation date of this file, if I copy this to another location, the copied file had its creation date reverted to today. To make matters worst, I have to copy these 10000 files (with their creation dates changed) to a windows 7 system and had these files with these old creation times. But if they are going to revert to today and I won't have powershell there, how can I resolve my problem?

1 Answers1

0

All the answers you are after is in the PowerShell help files.

# Get a list of all functions
Get-Command -CommandType Function | 
Out-GridView -PassThru -Title 'Available functions'


# Get a list of all commandlets
Get-Command -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available cmdlets'


# Get a list of all functions for the specified name
Get-Command -Name '*ADGroup*' -CommandType Function | 
Out-GridView -PassThru -Title 'Available named functions'


# Get a list of all commandlets for the specified name
Get-Command -Name '*ADGroup**'  -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available named cmdlet'


# get function / cmdlet details
(Get-Command -Name Get-ChildItem).Parameters
Get-help -Name Get-ChildItem -Examples
Get-help -Name Get-ChildItem -Full
Get-help -Name Get-ChildItem -Online


(Get-Command -Name ForEach).Parameters
Get-help -Name ForEach -Examples
Get-help -Name ForEach -Full
Get-help -Name ForEach -Online


(Get-Command -Name Copy-Item).Parameters
Get-help -Name Copy-Item -Examples
Get-help -Name Copy-Item -Full
Get-help -Name Copy-Item -Online


# Get parameter that accept pipeline input
Get-Help Get-ChildItem -Parameter * | 
Where-Object {$_.pipelineInput -match 'true'} | 
Select * 


Get-Help about_*
Get-Help about_Functions

Or just use the built-in robocopy to copy source to destination.

robocopy <Source> <Destination> [<File>[ ...]] [<Options>]

Take a look at the options for the /COPY:[copyflags] and /DCOPY switches.

# As per the ROBOCOPY /? usage info:
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
                      (copyflags : D=Data, A=Attributes, T=Timestamps).
                      (S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

/DCOPY:T :: COPY Directory Timestamps.


# For example:
ROBOCOPY c:\src d:\dest /MIR /COPY:DT /DCOPY:T


# Will copy all files and folders and preserve the date and time stamps.
ROBOCOPY c:\src d:\dest /MIR /COPY:DAT /DCOPY:T


Will copy all files and folders and preserve the date & time stamps and file attributes.

There is also another (and I believe deprecated?) switch /TIMFIX which does much the same as /COPY:DT but it doesn't fix the time stamps on folders.
postanote
  • 5,136