taljacob2 / edit-date-of-file

A script that edits the: "last modified date", "creation date" and "last access date" of a file or a folder.
MIT License
0 stars 0 forks source link

How can I use this script as part of a BAT script? #1

Open paolosezart opened 6 months ago

paolosezart commented 6 months ago

I would like to embed your ps1 script into my bat script. I would not like to create unnecessary files and I want the ps1 script to be executed inside a regular bat script. Is it possible?

taljacob2 commented 6 months ago

Hi @paolosezart

Yes, it is possible. Just make sure not to use double quotation marks ("") when passing parameters to the powershell script, as they may interfere with the powershell command.

For example, in the Get-Date('2020-12-31T23:54:43') parameter we should use single quotation marks ('') for the date and not double quotation marks ("").

These are examples of calling the powershell script inline without cloning, from a batch script:

@echo off

REM Example for calling the powershell script inline without cloning.
powershell -c "& ([scriptblock]::Create((iwr https://raw.githubusercontent.com/taljacob2/edit-date-of-file/master/edit-date-of-file.ps1 -useb))) -Path demo.txt -NewDate (Get-Date('2020-12-31T23:54:43'))"

REM With `-NoLogo -ExecutionPolicy Bypass`
powershell -NoLogo -ExecutionPolicy Bypass -c "& ([scriptblock]::Create((iwr https://raw.githubusercontent.com/taljacob2/edit-date-of-file/master/edit-date-of-file.ps1 -useb))) -Path demo.txt -NewDate (Get-Date('2020-12-31T23:54:43'))"

REM As an asynchronous process.
start /I powershell -NoLogo -ExecutionPolicy Bypass -c "& ([scriptblock]::Create((iwr https://raw.githubusercontent.com/taljacob2/edit-date-of-file/master/edit-date-of-file.ps1 -useb))) -Path demo.txt -NewDate (Get-Date('2020-12-31T23:54:43'))"

GOTO :EOF

Does this answer your question?