Questions tagged [rename-item-cmdlet]

Rename an item (a folder or a file) using rename-item powershell cmdlet

Rename-Item is used to rename a file or a folder. Takes two parameters -

  • Current Full path of the file/folder
  • New name

    Rename-Item "C:\My Documents\test.txt" new_test.txt

The aliases "rni" and "ren" also have the same affect.

83 questions
1
vote
1 answer

Powershell - Add extension to files containing dots

I have a script that addes the extension .xml to files without an extension. Get-ChildItem "C:\TEST" -file "*." | rename-item -NewName {"{0}.xml" -f $_.fullname} This works perfectly for a file such as: BC Logistics SPA con Socio Duo - 2022-03-31 -…
1
vote
0 answers

Rename files & append Number in Powershell

I'm trying to write a powershell script to rename several files. Their file names are originally long alphanumeric strings that I'm hoping to rename to something more generic and add number to the end. Something like file1, file2, file3, etc. I'm…
locutus
  • 11
  • 1
1
vote
2 answers

Rename-Item fails with 'Cannot rename because item at 'C:\Folder\ Example App Folder ' does not exist

I have a folder that has 100s of subfolders and files within those subfolders that have names with leading and trailing spaces. These folders and files were created using a Node JS app. I need to now remove the leading and trailing spaces from the…
1
vote
2 answers

Powershell to rename files with datetime formatted

I have a folder with media files named by timestamp like following yyyyMMdd_HHmmss_*.*. I need to rename them to yyyy-MM-dd HH-mm-ss *.* For example I need to rename file 20181019_210353_BURST2.jpg to 2018-10-19 21-03-53 BURST2.jpg There is a my…
Loom
  • 9,768
  • 22
  • 60
  • 112
1
vote
1 answer

Using the rename-item command to overwrite an existing file?

I'm trying to tidy up imported files from my iPhone using a PowerShell script, specifically wanting edited photos (IMG_E001.jpg) to overwrite the non-edited photos (IMG_001.jpg). I'm using the rename-item but can't figure out how to get it to…
Nick
  • 3,745
  • 20
  • 56
  • 75
1
vote
0 answers

More than one Rename-Item in Foreach (PS)

I got multiple files on a folder and I am trying to make a script that does this: Change the file extension to txt Replace all periods . to underscores _ Get content inside the text file and rename it depending on the content it took I want the…
1
vote
0 answers

Powershell issue renaming many files to remove certain characters

I have a foler which contains a few thousand PDFs named like XXX_CON.100.1.pdf, XXX_CON.101.1.pdf etc. I just want to remove the characters 'XXX_' from all filenames but I simply cannot get this to work. I have tried the following…
nzmike
  • 578
  • 1
  • 7
  • 25
1
vote
3 answers

Renaming multiple files with different names

I am a programmer by no means and am brand new to using powershell, but have been tasked with setting up some batch export processes for daily files we FTP. I need to come up with a script that will take changing file names and change them within…
SpudmanChu
  • 11
  • 1
1
vote
1 answer

adding text to folders with no files/and with no subfolders with files

I have code I put together from different sources found online. That code, I believe, is supposed to search and find all folders who have no files/and whose subfolders have no files, then add the text "NA -" to the beginning of these folders. When I…
1
vote
2 answers

'Rename-Item' makes a copy with the new name

Trying to make a script to backup specific folders and then rename the GUID key for the target user under HKLM...\ProfileLists but the rename-item command makes a copy of the key and creates a new key with the appended name though having full…
1
vote
3 answers

How to include variable in -Newname in powershell

Via power-shell script, trying to add $Album variable to naming sequence. Tried write host, variable is working. Have tried things like () [] {} "" '' . ect. The goal is to get $Album to work in this line below: {0:D2}$Album.mxf $i = 1 $Artist…
user7811302
1
vote
1 answer

Rename file before copy to certain folder

I´m a newbie still and learning to create PowerShell scripts to make Life in IT easier. At present I´m trying to build a script, which runs a certain Microsoft tool, scanning defined network shares in a csv file and creating an JSON output file. Now…
1
vote
2 answers

How to convert the contents of a variable to a string?

I have 5 variables and I have 3 files. $NumOne = Read-Host 'Enter four digit numone' $NumTwo = Read-Host = 'Enter two digit numtwo' $sdataJRN= $NumOne + $NumTwo + "00" + ".jrn" $sdataJNM = $NumOne + $NumTwo + "00" + ".jnm" $sdataTXN = $NumOne +…
Tony Tyne
  • 13
  • 2
1
vote
1 answer

PowerShell Rename-Item is looping until file reaches character limit

I have to rename literally thousands of folders and want to use a script which adds "Old" in front of the old Name. I tried this script Get-ChildItem | rename-item -NewName { "Old+ $_.Name } It even works when I try it in some small test folders…
weda
  • 11
  • 2
1
vote
4 answers

How to move first 7 characters of a file name to the end using Powershell

My company has millions of old reports in pdf form. They are Typically named in the format: 2018-09-18 - ReportName.pdf The organization we need to submit these to is now requiring that we name the files in this format: Report Name - 2018-09.pdf I…