There's reg files in the archive to install/remove from the context menu.
It's assumed that
AddDate.ps1 lives in C:\Scripts - edit the reg files if it doesn't.
AddDate.ps1param (
[string]$file = $(throw "AddDate.ps1 <file>")
)
$sDate = ("{0:MM}" -f (Get-Date)) + ("{0:dd}" -f (Get-Date)) + ("{0:yy}" -f (Get-Date))
$sNewName = (Get-Item $file).BaseName + ' ' + $sDate + (Get-Item $file).Extension
Rename-Item $file $sNewName
Limited testing here but it worked, eg.
AddDate.ps1 renamed to
AddDate 121615.ps1If you don't like the CLI window that opens you could use
cmdow with the /HID switch.
EDIT: Added
-ExecutionPolicy Bypass -NoProfile to reg entry so there's no need to modify Powershell ExecutionPolicy globally.
AddDate_Install.regWindows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Add Date to Filename]
@=""
[HKEY_CLASSES_ROOT\*\shell\Add Date to Filename\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -sta -ExecutionPolicy Bypass -NoProfile -Window Hidden C:\\\\Scripts\\\\AddDate.ps1 --% '%1'"
AddDate_Remove.regWindows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\*\shell\Add Date to Filename]
UPDATE: There was a problem calling the script on file names with spaces occasionally, changed the reg entry to call PoSh directly and replaced quotes around file arg which seems to have fixed it.