I am trying to add the Date field to multiple files in one specific folder.
Alle file names are in the same folder and are set up like: Name.docx
I now want to add the Date to all of them:
01022017_Name.docx
I do not want the Creation date, nor Last modified, also not the date of today, I need the Date field of Windows. See the link below for a print screen of my File Explorer folder. As you can see, only the Date column has relevant information.
Thanks for your response. It is the first time ever I am using PowerShell so I am not sure how to copy your code.
I just opened PowerShell and I pasted your code with my folder structure. Now I get the error: Get-ChildItem : A positional parameter cannot be found that accepts argument ‘batch\Documents’.
This is the code I am using. What am I doing wrong?
Thanks for your response. I am a beginner indeed. I only need to solve this hurdle for work, real quick. Unfortunately, I do not have the time to take multiple courses on how to code in PowerShell. I was hoping this forum was the location to ask for help in writing the correct code.
When I run your code, it runs, but nothing happens. I get a list of What ifs:
[pre]
What if: Performing the operation “Rename File” on target “Item: C:\Users\myname\Documents\Clients\Client\project name\Documents received\foldername(PKE7CG ajoarvot 2160) .docx Destination: C:\Users\myname\Documents\Clients\Client\project name\Documents received\foldername\04472020_(PKE7CG ajoarvot 2160) .docx”.
[/pre]
It does this for every line, but it does not change anything to the actual document name in my folder.
Also: it added 04472020, which is not a date and not the date I need.
You will have to learn at least a little bit about the cmdlets you’re about to use. You should never ever use code you don’t fully understand in a productive environment.
Please read at least the help for the cmdlet Rename-Item … especially the parameter -WhatIf.
Thanks for the link to the Whatif section. Now I see that the code would give me a wrong output.
How can I get the date of Windows instead of the 04472020?
I already read a lot on the NewName code before posting my question here. Unfortunately everything I could find online was linked to replacements and creation dates, never the “Date” field in Windows.
[quote quote=208794]How can I get the date of Windows instead of the 04472020?
… never the “Date” field in Windows.[/quote]
What do you mean with “date of Windows” and “Date field in Windows”?
Please keep in mind that we cannot see your screen and we cannot read your mind. You should be as explicit as possible when you ask questions in a technical forum. Try do provide every single piece of information for the helper to understand what you’re talking about. We’re all on different systems and in different environments. So you should not think of anything to be logic or given or set by default.
I tried to do just that… I posted an image in my opening post to make it as clear as possible.
In windows you have different columns, creation date of the file, last modified date and apparently also a column named “Date” (see my print screen on the link in the opening post).
This is the date I need. It is the creation date of the file by the content creator. I just copied all the documents in my own folder, so now creation date and last modified changed to the 4th of March when I did this action. Apparently the Date field still holds the information I need. I do not know what the technical name of this field is, to request it via PowerShell.
Mmmhh damn… I ran your code and turns out PowerShell does not find the “Date” field in Windows Explorer. For every possible date I get the 4th of March. You can find a print screen here: https://imgur.com/oVR0DQ1
The 4th of March was my creation date in Windows Explorer (see my opening post).
Hmmm … if I run this command I get actually 6 different time stamps …
CreationTime
CreationTimeUtc
LastAccessTime
LastAccessTimeUtc
LastWriteTime
LastWriteTimeUtc
The “Date” column in my Windows Explorer is equal to the “LastWriteTime”.
Despite the fact that you’re not showing the same files you might have an issue with your Windows system. I don’t think that’s a Powershell problem. Can you reproduce the effect with another computer and maybe with other file types?
How can it be an issue with Windows? My Windows Explorer shows the exact Date, right? But it looks like the “Date”-field in Windows Explorer is not one of your date fields below? - I don’t know how I can figure out what the field name is of the Date-field.
CreationTime
CreationTimeUtc
LastAccessTime
LastAccessTimeUtc
LastWriteTime
LastWriteTimeUtc
Yes, the creation date of these files is 2-3 years ago. I will prove it to you. You saw the Date-field in Windows explorer, it says 8/2/2017 for the first file. When I open this first file, you see the date: https://imgur.com/mcJ5Ik7 (this is a print screen of the info section of the Word-document)
The date I want in my file name is THIS date, 8/2/2017.
So I want a file name something like: 20170208_(PKE7CG ajoarvot 2160).docx
Somehow this date is still stored in Windows Explorer in the Date-field. Unfortunately I do not know the technical name of this field to retrieve it in PowerShell. When I run PowerShell with your code, the only dates I get are the dates of when I downloaded the documents to my computer (3/4/2020 - as you see in every print screen I posted in older posts).
Could you try to copy this file to a computer where no Microsoft Word is installed and try it there again. I could imagine that the explorer reads the metadata from inside the word file. That shouldn’t be possible where word isn’t installed. The bad news would be that you’d need to read the Word internatl metadata to use this date.
Finding a computer with no Word installed? Wut?
Both my work computer and my private laptop have Word installed. If I ask a friend who has a Mac computer, I don’t know if they have access to PowerShell…
I think it’s going to be easier and faster to just adjust all of the files manually. I don’t see the ending of this story anymore …
Thanks for your time though Olaf … Appreciate the effort!