Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename-Item with Date and Time for excel file

Status
Not open for further replies.

WASP56

Programmer
Nov 16, 2018
1
US
Hello,

First Time user to this forum: I have a excel file called "Final_Output_z.xlsx. I am using the following in my Powershell to add the Date and Time but keep running into error:

Rename-Item : A positional parameter cannot be found that accepts argument '11/16/2018 10:57:42 AM'.
At line:1 char:1
+ Rename-Item -Path "C:\Users\Documents\MicroApps\SCAPH_AC ...

Powershell code I am using:

Rename-Item -Path "C:\Users\Documents\MicroApps\SCAPH_ACL_Project\1_SCAPH_Main\Final_Output_z.xlsx" -NewName "Final_Output_z.xlsx" (Get-Date) -format "yyyy MMM d"

WASP56
 
It's not the most elegant, but this should work

Code:
Get-ChildItem "C:\Users\Documents\MicroApps\SCAPH_ACL_Project\1_SCAPH_Main\Final_Output_z.xlsx" | ForEach-Object {$_.LastWriteTime = Get-Date; Rename-Item -Path $_ -NewName "Final_Output_z.xlsx"}


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top