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.
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.
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.
get-childitem -path $path | rename-item -newname { [io.path]::ChangeExtension($_.name, “.backup”) }
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
}
}
Get-ChildItem -Path \\path\ -Recurse -File | Rename-Item -NewName {$_.Name + '.backup'} -WhatIf