Remove-Item: Cannot remove item The process cannot access the file

I use this script, but return error Remove-Item: Cannot remove item c:\files\images\images.tif The process cannot access the file.Can I help me, please? Thank you.

$Path = "c:\files\images\"
    Get-ChildItem ($Path+"\*.tif") | %{ $file = new-object System.Drawing.Bitmap($_.FullName); $file.Save(( Join-Path "\\server\upload\" ($_.Name -replace "tif", 'jpg') ),"JPEG"); $file="" }
    Get-ChildItem ($Path+"\*.*") -Recurse | Remove-Item -Force

Hmmm … I’d start with formatting the code nicely. It makes it easier to read and to understand …

$Path = "c:\files\images\"
Get-ChildItem ($Path + "\*.tif") | 
    ForEach-Object { 
        $file = new-object System.Drawing.Bitmap($_.FullName)
        $file.Save(( Join-Path "\\server\upload\" ($_.Name -replace "tif", 'jpg') ), "JPEG")
        $file = "" 
Get-ChildItem ($Path + "\*.*") -Recurse | 
    Remove-Item -Force

Then I’d start to try to simplify my code. If I’m not wrong you want to move all *.tif files to a server and rename them at the same time to *.jpg files, right?
You can move and rename files in PowerShell with Move-Item.

So … how about this?

$Path = 'c:\files\images\'
Get-ChildItem ($Path + '*.tif') | 
ForEach-Object { 
    $NewFileName = Join-Path -Path '\\server\upload\' -ChildPath  ($_.BaseName + 'jpg') 
    Move-Item -Path $_.FullName -Destination $NewFileName

Super. Everything works fine.Thank you