Saturday, May 2, 2020

Adding a datestamp to a filename in powershell 7 in Debian 10

create a test file

new-item -type file -name test.txt

$filename="\home\sourav\test.txt"

$todaysdate=get-date -Format MMddyy

$file=Get-ChildItem $filename  

$newfilename=$file.BaseName+"."+$todaysdat+$file.Extension

Rename-Item -path $filename -NewName $newfilename -verbose

No comments:

Post a Comment