Author Posts

June 5, 2018 at 4:32 pm

Hello –
I am trying to create a script that will be contained in file distributions that copies the files contained and renames the existing files at the endpoint to *.backup – The files do not have uniform extensions, or names.

June 5, 2018 at 5:05 pm

Have you tried anything? Maybe a search for Powershell Rename File. We're happy to help if you're having issues, but this isn't a script writing service.

June 5, 2018 at 5:30 pm

So far I have tried a couple dozen versions. Apologies for not having posted them.
Im new to powershell, so im struggling to understand how each of the objects is being processed and what I can use as a wildcard and what I cannot.
This is what I have been trying to get working
get-childitem -path $path | rename-item -newname (*.*, *.backup)
I have tried a large number of different methods to change the wild cards including *_.name, "name.$_", $_.

Im not needing a script written, Just need to understand how to create the correct wild card after -newname to leave the file name, and change only the extension.

June 5, 2018 at 5:48 pm

https://stackoverflow.com/questions/12120326/how-do-i-change-the-extension-of-many-files-in-a-directory

get-childitem -path $path | rename-item -newname { [io.path]::ChangeExtension($_.name, ".backup") }

June 5, 2018 at 10:03 pm

End result
Files = Get-ChildItem -path $path -Recurse | Select-Object -ExpandProperty Name
Foreach ($File in $Files)
{
IF ($File -like '*.*')
{
Rename-Item -Path $path\$File -NewName "$file.backup" -Force
}
else
{
$false
}
}

June 5, 2018 at 11:28 pm

Get-ChildItem -Path \\path\ -Recurse -File | 
Rename-Item -NewName {$_.Name + '.backup'} -WhatIf