I am trying to write a script in powershell to remove the first 20 characters of every MP3 filename in a folder, I have created a file ‘test.ps’ and inserted the powershell code below into it,
gci *.mp3 | rename-item -newname { [string]($_.name).substring(20) }
When I run this file in powershell.exe nothing happens,
Can anyone help? Thanks.
This may get you started. (There are probably much more concise ways, but this works and is readable when you need to maintain it later. 🙂 )
I created a folder
C:\TempFiles, and created the following files in that folder:(I created them the old-fashioned way, I’m afraid. <g>. I used
from an actual command prompt.)
I then opened
PowerShell ISEfrom the start menu, and ran this script. It creates an array ($files), containing only the names of the files, and processes each of them:This left the folder containing:
In order to run a script from the command line, you need to change some default Windows security settings. You can find out about them by using
PowerShell ISE‘s help file (from the menu) and searching forabout_scriptsor by executinghelp about_scriptsfrom theISEprompt. See the sub-sectionHow To Run A Scriptin the help file (it’s much easier to read).