I have two folders all with multiple .msg files I need to add a numerical, sequential prefix to. One folder has over 1500 individual files.
I want the end result to go from this:
"[EXTERNAL] RE%3A Auth....msg"
"Fees....msg"
"Hello There...msg"
To this:
"1[EXTERNAL] RE%3A Auth....msg"
"2Fees....msg"
"3Hello There...msg"
I have tried to combine a few results from other similar threads I have found here and have come up with the following:
$i = 1
@Get-ChildItem *.msg | %{Rename-Item $_ -NewName ("{0:000#}_$($_.directory.name).msg" -f $i++)}
When I run this script, I get the following errors:
At C:\users\me\Documents\PrependNumbers.ps1:10 char:5
+ @Get-ChildItem *.msg | %{Rename-Item $_ -NewName ("{0:000#}_$($_.dire ...
+ ~~~~~~~~~~
Unexpected token '-ChildItem' in expression or statement.
At C:\users\me\Documents\PrependNumbers.ps1:10 char:16
+ @Get-ChildItem *.msg | %{Rename-Item $_ -NewName ("{0:000#}_$($_.dire ...
+ ~~~~~
Unexpected token '*.msg' in expression or statement.
At C:\users\me\Documents\PrependNumbers.ps1:10 char:1
+ @Get-ChildItem *.msg | %{Rename-Item $_ -NewName ("{0:000#}_$($_.dire ...
+ ~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@Get' can be used only as an
argument to a command. To reference variables in an expression use '$Get'.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
I feel like I probably just have a syntax error somewhere, but am unable to tell where exactly from these errors.