I have the following PnP PowerShell to get the URL of a file and remove the ".lock" string from the file name using Replace
:-
$url = $item.File.ServerRelativeUrl
Write-Host "$(Get-Date) - ($($Counter)/$($AllItems.Count)) - Restoring version $VersionLabel for $($Item.File.Name)"
$item.File.Versions.RestoreByLabel($VersionLabel)
Invoke-PnPQuery
$restoedFile = Get-PnPFile -Url $url
Write-Host "2) -->"
url2 = $url.Replace(".lock","")
Write-Host "1) $url" $url
Write-Host "3) $url2" $url2
But this code url2 = $url.Replace(".lock","")
will return empty string. Any advice?
url2 = $url.Replace(".lock","")
in this line I cannot see $ for variableurl2
. It may be throwing exception. It should be$url2 = $url.Replace(".lock","")