SOLVED

Rename files to get the year, month and day of the creation in front of the file?

%3CLINGO-SUB%20id%3D%22lingo-sub-3374932%22%20slang%3D%22en-US%22%3ERename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3374932%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%20I%20am%20a%20trainee%20and%20need%20to%20make%20some%20changes%20to%20the%20file%20naming%20convention.%3C%2FP%3E%3CP%3EThere%20are%20tens%20of%20thousands%20of%20files%20in%20the%20filesystem%20and%20it%20would%20be%20a%20long%20day%20to%20do%20it%20all%20manually.%3C%2FP%3E%3CP%3ESo%20my%20question%20is%20how%20to%20make%20it%20possible%20with%20a%20script%20to%20automate%20this%20process.%3C%2FP%3E%3CP%3EIt%20would%20be%20nice%20to%20run%20the%20script%20into%20the%20start%20folder%20or%20select%20the%20start%20point%20and%20from%20there%20go%20downwards%20into%20all%20folders%20to%20get%20the%20name%20and%20creation%20date%20of%20a%20file%20that%20does%20not%20match%20the%20naming%20convention%20mentioned.%3C%2FP%3E%3CP%3ESo%20that%20any%20file%20e.g.%20%22logo.png%22%20or%20%22hello.world_2021.pdf%22%20which%20was%20created%20on%2005%2F05%2F2021%20will%20look%20like%20%2220210505_logo.png%22%20and%20%2205052021_hello.world_2021.pdf%22%20afterwards.%3C%2FP%3E%3CP%3EAnd%20any%20file%20that%20contains%20the%20year%2C%20month%20and%20day%20at%20the%20beginning%20should%20be%20ignored.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3374932%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3375034%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3375034%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390158%22%20target%3D%22_blank%22%3E%40pspBugs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20isn't%20difficult%20to%20add%20a%20date-based%20prefix%2C%20but%20you've%20provided%20two%20different%20formats%20in%20your%20example%20below%20(yyyyMMdd_%20and%20ddMMyyyy_.)%20Which%20is%20your%20preference%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20are%20you%20sure%20you%20want%20the%20creation%20date%2C%20not%20the%20last%20modified%20date%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ELain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3375078%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3375078%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390158%22%20target%3D%22_blank%22%3E%40pspBugs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20a%20three-line%20example%20on%20how%20you%20can%20do%20this.%20I've%20gone%20with%20the%20assumptions%20that%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EThe%20prefix%20date%20format%20should%20be%20%22yyyyMMdd_%22%3B%3C%2FLI%3E%3CLI%3EYou%20do%20indeed%20want%20the%20creation%20date%20used%20in%20the%20prefix%2C%20not%20the%20last%20modified%20date.%3C%2FLI%3E%3C%2FOL%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24ParsedDate%20%3D%20%5Bdatetime%5D%3A%3AMinValue%3B%0A%24Path%20%3D%20%22D%3A%5CData%5CSomePath%22%3B%0AGet-ChildItem%20-File%20-Path%20%24Path%20-Recurse%20%7C%0A%20%20%20%20Where-Object%20%7B%20(-not%20%5Bregex%5D%3A%3AIsMatch(%24_.Name%2C%20%22%5E%5Cd%7B8%7D_%22%2C%20%5BSystem.Text.RegularExpressions.RegexOptions%5D%3A%3AIgnoreCase))%20-or%20(-not%20%5Bdatetime%5D%3A%3ATryParseExact(%24_.Name.Substring(0%2C%208)%2C%20%22yyyyMMdd%22%2C%20%5Bcultureinfo%5D%3A%3ACurrentCulture%2C%20%5BSystem.Globalization.DateTimeStyles%5D%3A%3ANone%2C%20%5Bref%5D%20%24ParsedDate))%20%7D%20%7C%0A%20%20%20%20%20%20%20%20ForEach-Object%20%7B%20Rename-Item%20-Path%20(%24_.FullName)%20-NewName%20%22%24(%24_.CreationTime.ToString(%22yyyyMMdd%22))_%24(%24_.Name)%22%3B%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ELain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3375555%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3375555%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20that%20was%20fast.%20Thank%20you%20so%20much.%3CBR%20%2F%3EYes%20the%20year%20musst%20be%20in%20front.%3CBR%20%2F%3EI%20will%20try%20it%20as%20soon%20as%20possible%2C%20but%20it%20looks%20great.%3CBR%20%2F%3E%3CBR%20%2F%3EBy%20the%20way%20where%20should%20I%20start%20with%20training%20for%20Powershell%3F%20Is%20there%20a%20course%20or%20a%20training%20book%20or%20something%20else%3F%3CBR%20%2F%3E%3CBR%20%2F%3EpspBugs%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CSTRONG%3EEDIT%3C%2FSTRONG%3E%3A%3C%2FP%3E%3CP%3EI%20tested%20the%20code%20and%20it%20worked%2C%20but%20it%20did%20not%20take%20the%20creation%20date%20of%20each%20file%20every%20time.%3C%2FP%3E%3CP%3ESo%20it%20takes%20the%20date%20from%20when%20the%20script%20was%20executed.%20Is%20there%20any%20way%20to%20loop%20this%20and%20get%20the%20individual%20creation%20date%20of%20each%20file%3F%3CBR%20%2F%3EAnd%20on%20repeated%20execution%2C%20the%20already%20renamed%20files%20are%20not%20ignored.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EpspBugs%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3375992%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3375992%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390158%22%20target%3D%22_blank%22%3E%40pspBugs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAre%20you%20sure%20you%20don't%20want%20the%20last%20modified%20date%20instead%3F%26nbsp%3BHere's%20an%20example%20to%20illustrate%20why%20I%20ask.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20the%20sample%20files%20I%20tested%20against.%20Windows%20Explorer%20shows%20the%20date%20modified%20by%20default%2C%20not%20the%20creation%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt's%20important%20to%20note%20I%20copied%20these%20files%20from%20a%20different%20location%2C%20%3CEM%3Emeaning%20the%20originals%20have%20a%20different%20creation%20date%3C%2FEM%3E.%20This%20diminishes%20the%20value%20of%20the%20creation%20time%20since%20it%20may%20not%20actually%20be%20the%20date%20the%20author%20created%20the%20file%20at%20all%2C%20but%20simply%20the%20last%20time%20it%20was%20copied.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22LainRobertson_1-1652576459207.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371705iAA09B09BAD6F7EEF%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22LainRobertson_1-1652576459207.png%22%20alt%3D%22LainRobertson_1-1652576459207.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20to%20be%20sure%2C%20let's%20have%20a%20look%20at%20the%20dates%20on%20the%20%22input.settings%22%20file%20in%20PowerShell%2C%20noting%20CreationTime%20in%20particular.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22LainRobertson_0-1652576417862.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371704i6C892E1A3D6D3F09%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22LainRobertson_0-1652576417862.png%22%20alt%3D%22LainRobertson_0-1652576417862.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%2C%20you%20can%20see%20that%20the%20CreationTime%20is%20today%20(the%20actual%20time%20I%20performed%20the%20file%20copy)%20and%20that%20it%20is%20actually%20greater%20than%20the%20LastWriteTime.%20Now%2C%20this%20is%20all%20well%20and%20good%20from%20the%20file%20system%20perspective%20where%20it%20makes%20sense%2C%20but%20it's%20probably%20counterintuitive%20to%20what%20you're%20hoping%20to%20achieve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20short%2C%20the%20CreationTime%20is%20somewhat%20unreliable%2C%20whereas%20the%20LastWriteTime%20is%20preserved%20even%20during%20the%20any%20copy%20process.%20This%20is%20why%20I%20was%20wondering%20if%20you%20wouldn't%20prefer%20the%20last%20modified%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20script%20itself%20is%20not%20using%20the%20current%20date%20through%20some%20indirect%20means%20(like%2C%20say%2C%20%5Bdatetime%5D%3A%3ANow).%20It%20really%20is%20pulling%20the%20CreationTime%20from%20the%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ELain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3376086%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3376086%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1390158%22%20target%3D%22_blank%22%3E%40pspBugs%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20noticed%20your%20second%20comment%20about%20existing%20prefixes%20not%20being%20ignored.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20seeing%20that%20reflected%20when%20I%20run%20it%20multiple%20times%20over%20the%20test%20files.%20It's%20putting%20the%20prefix%20in%20the%20first%20time%20then%20ignoring%20it%20on%20subsequent%20runs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMaybe%20you%20can%20drop%20an%20example%20into%20this%20thread%20so%20we%20can%20get%20an%20idea%20of%20what's%20going%20on%20behind%20the%20scenes%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20could%20drop%20in%20the%20following%20for%20one%20of%20the%20repeatedly-changing%20files%2C%20that%20might%20help%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EFile%20name%3B%3C%2FLI%3E%3CLI%3EFile%20creation%20date%3B%3C%2FLI%3E%3CLI%3EWhich%20version%20of%20PowerShell%20you're%20running%20(I'm%20running%20under%20Windows%20PowerShell%205.1.)%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20get%20points%201%20and%202%20via%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-Item%20-Path%20%22.%5CSomeFileName%22%20%7C%20Select-Object%20-Property%20Name%2C%20CreationTime%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20get%20point%203%20from%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24PSVersionTable%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ELain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3383128%22%20slang%3D%22en-US%22%3ERe%3A%20Rename%20files%20to%20get%20the%20year%2C%20month%20and%20day%20of%20the%20creation%20in%20front%20of%20the%20file%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3383128%22%20slang%3D%22en-US%22%3EFirst%20of%20all%20sorry%20for%20the%20late%20answer.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20tried%20the%20script%20at%20home%20first%20and%20found%20this%20strange%20behavior%20I%20discribed%20above.%20But%20at%20work%2C%20and%20now%20at%20home%2C%20I%20could%20not%20reproduce%20it%20again.%3CBR%20%2F%3E%3CBR%20%2F%3ETo%20answer%20the%20question%2C%20here%20are%20the%20answers%20from%20Powershell%20for%20questions%201%20to%203.%3CBR%20%2F%3E%3CBR%20%2F%3E%22PS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20Get-Item%20-Path%20%22C%3A%5CUsers%5Cuser%5CDownloads%5Cjhjk%5CTest%5C20220514_yyyyMMdd_rename.ps1%22%20%7C%20Select-Object%20-Property%20Name%2C%20CreationTime%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%24PSVersionTable%22%3CBR%20%2F%3E%3CBR%20%2F%3EName%20CreationTime%3CBR%20%2F%3E----%20------------%3CBR%20%2F%3E20220514_yyyyMMdd_rename.ps1%2005%2F16%2F2022%2021%3A04%3A34%3CBR%20%2F%3E%3CBR%20%2F%3EName%20Value%3CBR%20%2F%3E----%20-----%3CBR%20%2F%3EPSVersion%205.1.19041.1645%3CBR%20%2F%3EPSEdition%20Desktop%3CBR%20%2F%3EPSCompatibleVersions%20%7B1.0%2C%202.0%2C%203.0%2C%204.0...%7D%3CBR%20%2F%3EBuildVersion%2010.0.19041.1645%3CBR%20%2F%3ECLRVersion%204.0.30319.42000%3CBR%20%2F%3EWSManStackVersion%203.0%3CBR%20%2F%3EPSRemotingProtocolVersion%202.3%3CBR%20%2F%3ESerializationVersion%201.1.0.1%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20Thank%20you%20for%20the%20Help.%3CBR%20%2F%3E%3CBR%20%2F%3EpspBugs%3C%2FLINGO-BODY%3E
New Contributor

Hi all, I am a trainee and need to make some changes to the file naming convention.

There are tens of thousands of files in the filesystem and it would be a long day to do it all manually.

So my question is how to make it possible with a script to automate this process.

It would be nice to run the script into the start folder or select the start point and from there go downwards into all folders to get the name and creation date of a file that does not match the naming convention mentioned.

So that any file e.g. "logo.png" or "hello.world_2021.pdf" which was created on 05/05/2021 will look like "20210505_logo.png" and "05052021_hello.world_2021.pdf" afterwards.

And any file that contains the year, month and day at the beginning should be ignored.

 

Thanks for the help.

6 Replies

@pspBugs 

 

It isn't difficult to add a date-based prefix, but you've provided two different formats in your example below (yyyyMMdd_ and ddMMyyyy_.) Which is your preference?

 

And are you sure you want the creation date, not the last modified date?

 

Cheers,

Lain

best response confirmed by pspBugs (New Contributor)
Solution

@pspBugs 

 

Here's a three-line example on how you can do this. I've gone with the assumptions that:

 

  1. The prefix date format should be "yyyyMMdd_";
  2. You do indeed want the creation date used in the prefix, not the last modified date.
$ParsedDate = [datetime]::MinValue;
$Path = "D:\Data\SomePath";
Get-ChildItem -File -Path $Path -Recurse |
    Where-Object { (-not [regex]::IsMatch($_.Name, "^\d{8}_", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)) -or (-not [datetime]::TryParseExact($_.Name.Substring(0, 8), "yyyyMMdd", [cultureinfo]::CurrentCulture, [System.Globalization.DateTimeStyles]::None, [ref] $ParsedDate)) } |
        ForEach-Object { Rename-Item -Path ($_.FullName) -NewName "$($_.CreationTime.ToString("yyyyMMdd"))_$($_.Name)"; }

 

Cheers,

Lain

Hey that was fast. Thank you so much.
Yes the year musst be in front.
I will try it as soon as possible, but it looks great.

By the way where should I start with training for Powershell? Is there a course or a training book or something else?

pspBugs


EDIT:

I tested the code and it worked, but it did not take the creation date of each file every time.

So it takes the date from when the script was executed. Is there any way to loop this and get the individual creation date of each file?
And on repeated execution, the already renamed files are not ignored.

 

pspBugs

@pspBugs 

 

Are you sure you don't want the last modified date instead? Here's an example to illustrate why I ask.

 

Here's the sample files I tested against. Windows Explorer shows the date modified by default, not the creation date.

 

It's important to note I copied these files from a different location, meaning the originals have a different creation date. This diminishes the value of the creation time since it may not actually be the date the author created the file at all, but simply the last time it was copied.

 

LainRobertson_1-1652576459207.png

 

Just to be sure, let's have a look at the dates on the "input.settings" file in PowerShell, noting CreationTime in particular.

 

LainRobertson_0-1652576417862.png

 

Here, you can see that the CreationTime is today (the actual time I performed the file copy) and that it is actually greater than the LastWriteTime. Now, this is all well and good from the file system perspective where it makes sense, but it's probably counterintuitive to what you're hoping to achieve.

 

In short, the CreationTime is somewhat unreliable, whereas the LastWriteTime is preserved even during the any copy process. This is why I was wondering if you wouldn't prefer the last modified date.

 

The script itself is not using the current date through some indirect means (like, say, [datetime]::Now). It really is pulling the CreationTime from the file.

 

Cheers,

Lain

@pspBugs  

 

I just noticed your second comment about existing prefixes not being ignored.

 

I'm not seeing that reflected when I run it multiple times over the test files. It's putting the prefix in the first time then ignoring it on subsequent runs.

 

Maybe you can drop an example into this thread so we can get an idea of what's going on behind the scenes?

 

If you could drop in the following for one of the repeatedly-changing files, that might help:

 

  1. File name;
  2. File creation date;
  3. Which version of PowerShell you're running (I'm running under Windows PowerShell 5.1.)

 

You can get points 1 and 2 via:

 

Get-Item -Path ".\SomeFileName" | Select-Object -Property Name, CreationTime

 

 

You can get point 3 from the following:

 

$PSVersionTable

 

 

Cheers,

Lain

First of all sorry for the late answer.

I tried the script at home first and found this strange behavior I discribed above. But at work, and now at home, I could not reproduce it again.

To answer the question, here are the answers from Powershell for questions 1 to 3.

"PS C:\WINDOWS\system32> Get-Item -Path "C:\Users\user\Downloads\jhjk\Test\20220514_yyyyMMdd_rename.ps1" | Select-Object -Property Name, CreationTime


$PSVersionTable"

Name CreationTime
---- ------------
20220514_yyyyMMdd_rename.ps1 05/16/2022 21:04:34

Name Value
---- -----
PSVersion 5.1.19041.1645
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1645
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

So Thank you for the Help.

pspBugs