|
Post by xxgeek on Mar 23, 2024 17:31:40 GMT
Thanks Pale, I've been waiting for this.
So it sounds like you have it conquered since you don't want to copy/paste anyway. I misunderstood Rods double quote idea thinking he meant using a quote with a chr$(34) as I had been. Didn't know we could double quote like what you have that is working.
I'll play around with what you have posted and re-post later.
Just for kicks - This code from Powershell command line lists all the possible formats. Quite extensive. Plus there are customizable options too. $d.GetDateTimeFormats()
|
|
|
Post by xxgeek on Mar 23, 2024 19:10:09 GMT
A couple of pages for info I found on date formats may interest you. www.sharepointdiary.com/2021/11/date-format-in-powershell.htmllearn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-stringsWhat works for you doesn't seem to work for me, and vice versa. Very tricky getting a syntax that works. If it works for you that's the main thing. It is possible the format you are dealing with was a customized format. This works using this line run from a one line script(if script written locally. A downloaded script wants confirmation, and Unblock switch used) $(get-item "+chr$(34)+path$+chr$(34)+").creationtime=$(get-date "+chr$(34)+newDate$+chr$(34)+")" or this in the powershell command line $(get-item "E:\Tests\000000 - Copys\doit.exe").creationtime=$(get-date 636880799200000000) produces March 13, 2019, 1:18:40 PM as the new creation date Whenever I try the double quotes, I get an error telling me my string of path$ is empty when it is NOT empty - I checked it. Possibly due to the fact I'm running a script with cmd to open powershell and change Execution policy, and you are running powershell directly. I don't know why, just a guess. Anyway, learning new stuff is always good for the soul.
|
|
|
Post by xxgeek on Mar 24, 2024 15:08:41 GMT
Save to disk before RUN'ing
Here is what is working for me. If I use a long windows date format I need 'no quotes' on the date, but 'do need' quotes on a normal date format.
It opens to a filedialog to choose a file, then changes the date to whatever is selected in the code for newDate$ (a few examples) or provide your own newDate$.
If you set the Hard code instead you can set it to a folder, or a file. If there is interest I could use a folderdialog to select a folder, or a file
'change file creation date 'by xxgeek Mar 20 2024 nomainwin q$=chr$(34) global path$, q$, newDate$ path$ = "Path_To_File" 'file to change creation Date eg: "c:\testing\myTestfile.txt filedialog "Select a File to Change it's Creation Date ","e:\*.*", path$ 'newDate$ = "634569545411520000" ' = November 15, 2011, 11:49:01 AM 'newDate$ = "636880799200000000" ' = March 13, 2019, 1:18:40 PM 'newDate$ = "636880598200000000" ' = March 13, 2019, 7:43:40 AM 'newDate$ = "626880598200000000" ' = July 5, 1987, 5:57:00 AM 'newDate$ = "624180398200000000" ' = December 14, 1978, 12:23:40 AM 'newDate$ = "05/06/2007 08:00 pm" 'newDate$ = "636860799200000000" ' = February 18, 2019, 9:45:20 AM
'change the newDate$ string but use one of the same formats listed '3 character abreviations of month or full name of month works newDate$ = "Nov 11 1956 09:00 pm" ' -works Month Day Year hour:minute pm or am 'newDate$ = "November 11 1956 09:00 pm" ' -works Month Day Year hour:minute pm or am 'newDate$ = "Sep 11 1956 09:00 pm" ' -works Month Day Year hour:minute pm or am 'newDate$ = "15 May 2007 08:00 am" ' - works Day Month Year hour:minute am or pm 'newDate$ = "15 Aug 2007 08:00 am" ' - works Day Month Year hour:minute am or pm 'newDate$ = "2/1/2015 2:00 am" ' - works Month/Day/Year hour:minute am or pm 'newDate$ = "01/13/2015 05:00 pm" '- works using 01 or just 1 and 05 or just 5 'newDate$ = "1/21/2015 5:00 pm" '- works using 01 or just 1 and 05 or just 5 'newDate$ = "2-11-2005 7:00 am" ' - works Month/Day/Year hour:minute am or pm 'newDate$ = "2-May-2015 7:00 am" ' - works Day/Month/Year hour:minute am or pm 'newDate$ = "June-10-2002 09:00 pm" ' -works Month Day Year hour:minute pm or am if path$ = "" or newDate$ = "" then end call writePs1 ' cmd/c closes command window when complete - ,hide hides it completely run "cmd.exe /k powershell Set-ExecutionPolicy -ExecutionPolicy unRestricted -Scope CurrentUser ";_ "& powershell .\change.ps1 & powershell Set-ExecutionPolicy -ExecutionPolicy";_ " unDefined -Scope CurrentUser"',hide end
sub writePs1 open DefaultDir$;"\change.ps1" for output as #change if right$(newDate$,4) = "0000" then #change "$(Get-Item ";q$;path$;q$;").creationtime=$(Get-Date ";newDate$;")" else #change "$(Get-Item ";q$;path$;q$;").creationtime=$(Get-Date ";q$;newDate$;q$;")" end if close #change end sub
|
|
Pale
Member in Training
Posts: 24
|
Post by Pale on Mar 25, 2024 22:01:06 GMT
My code works ok now . I have not been making a script but just sending a string direct to powershell. If i cut the printed version of this string from the mainwin direct to powershell it fails. Which is fine now i understand what happens. When I try your code above I get run "cmd.exe /c powershell Set-ExecutionPolicy -ExecutionPolicy unRestricted -Scope CurrentUser ";_ "& powershell .\change.ps1 write-host "_ "& powershell Set-ExecutionPolicy -ExecutionPolicy unDefined -Scope "_ "CurrentUser"',hide 'uncomment to hide black command window High lighted and BASIC Complie Halted : Syntax error Pale
|
|
|
Post by tsh73 on Mar 26, 2024 6:46:29 GMT
Looks like, on the end of lines 2 and 3, "_" should be ";_"
|
|
|
Post by xxgeek on Mar 26, 2024 11:55:43 GMT
oops, wrong code.
Fixed
|
|