#PSTip One way to change a file extension

Modifying a file always brings a risk of corrupting it; making a backup copy whenever possible is one of the file manipulation best-practices. One way of doing it is to create a copy with the same name and appropriate extension like ‘bak’. This task can be finished in a few different ways. Here is my favorite–using the Copy-Item cmdlet and the ChangeExtension() method of the System.IO.Path class:

$path = 'C:\temp\ImportantFile.txt'
Copy-Item -Path $path –Destination ([io.path]::ChangeExtension($path, '.bak')) -Verbose
Share on: